Hi, I'm new to C++ and my first assignment is to convert C code into C++ code.

Here I have a loop, however; I can't seem to get it to break out of the loop. It is suppose to input an odd number that is less than 15 and set the input to the pointer. Any help would be appreciated.

void CMatrix::GetData()
     int nInput = 0;

     for(;;) //infinite for loop
            cout << "\nEnter a positive,";
            cout << " odd integer (-1 to exit program):\n";
            cin >> nInput;
            pInput = &nInput;
//            cout << "Pointer " << *pInput << "\n" << nInput;
            //if numbers entered, enter the block
            if (cin.good()){
               if (nInput == -1){
               else if (nInput > 15){
                    cout << "Sorry, but the integer has";
                    cout << " to be less than 15.\n";
               else if (nInput%2 == 0){
                    cout << "Sorry, but the integer has to be odd.\n";
            }//end if cin.good()
            else if (!isdigit(nInput))
                 cout <<"Only digits are allowed!\n";
     }//end for loop
8 Years
Discussion Span
Last Post by d34dw4rd

put a break statement inside all of the if statement. Why not combine all of
the if statement and provide a generic error message, if the detailed
message is not important?


I can't just do that because I need it to keep asking until a correct number is imputed, so it should only break after either -1 or a correct number


ok I think i got it to work after putting a break on the main if statement however now I get an "Illegal System DLL Relocation" what is that?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.