Domain changed to archive.palanq.win . Feb 14-25 still awaits import.
[6 / 3 / ?]

Learning C++

No.566563 View ViewReplyOriginalReport
Something wrong with my while loop but I don't know what. I want the program to keep asking for values until you return something other than "y" or "Y". Thanks in advance. Here is the while loop code :

while (flag)
{
int choice = 0; int val1 = 0; int val2 = 0; int ans = 0;
cout << "Enter your choice (1-5): ";
cin >> choice;
cout << "\nEnter integer 1: ";
cin >> val1;
cout << "\nEnter integer 2: ";
cin >> val2;
if(choice < 0 || choice > 5)
{
cout << "\nEnter a choice between 1-5: ";
cin >> choice;
}
if (choice == 1)
{
ans = Add(val1,val2);
cout << "\nResult: " << ans << endl;
}
if (choice == 2)
{
ans = Subtract(val1,val2);
cout << "\nResult: " << ans << endl;
}
if (choice == 3)
{
ans = Multiply(val1,val2);
cout << "\nResult: " << ans << endl;
}
if (choice == 4)
{
ans = Divide(val1,val2);
cout << "\nResult: " << ans << endl;
}
if (choice == 5)
{
ans = Modulus(val1,val2);
cout << "\nResult: " << ans << endl;
}
char c_flag[1];
cout << "Press Y or y to continue: ";
cin >> c_flag;
if(c_flag == "y" || c_flag == "Y")
{
flag = true;
}
else
{
flag = false;
}
}