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){
break;
}
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";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
}//end for loop
}