if ( z == 1 )
{
add Num;
Num.getNum(x,y);
cout << Num.addition();
}
if ( z == 2)
{
Multiplication Numbers;
Numbers.getNum(x,y);
cout << Numbers.multiply();
}
else {
cout << "Please enter one or two : ";
//Here is the problem
}
cout << "Please enter one or two : ";
do
{
if ( z == 1 )
{
add Num;
Num.getNum(x,y);
cout << Num.addition();
}
elseif ( z == 2)
{
Multiplication Numbers;
Numbers.getNum(x,y);
cout << Numbers.multiply();
}
else {
cout << "Please enter one or two : ";
//Here is the problem
}
} while(z != 1 && z != 2);
No, I have a psychotic hatred for constructs like these:
} while(z != 1 && z != 2);
Better with a switch:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
bool valid = false;
while (!valid) {
switch (z) {
case 1:
valid = true; // after this case is executed, code continues after the while loop
// your code here, consider making it a function
break;
case 2:
valid = true;
// your code here
break;
default:
std::cout << "Please enter 1 or 2\n";
}
}