I am trying to write a program that has loops and answer these questions:
1.Request two integer numbers from the user.
2.Verify if the two numbers are between 0 and 10 (exclusive) and, if not, ask for the two numbers again until the conditions are met.
3.Instruct the user to enter the product of the two numbers.
4.If the product entered by the user is incorrect request the product from the user again with a message that the answer was incorrect. Keep requesting the number until the answer is correct.
5.When the product entered by the user is correct output a message specifying so and ask the user if he/she would like to start over.
6.If the answer to the question to start over is 1, start over, and, otherwise, end the program.
here is maybe a bit of the sample code for the loop I have to create for the program:
CPP / C++ / C Code:
CODE
#include <iostream>
using namespace std;
int main()
{
cout << "This is a while loop example \n";
bool done;
int userChoice;
done = false;
while (done == false)
{
cout << "Enter <1> to continue: ";
cin >> userChoice;
if (userChoice == 1)
{
done = true;
}
}
cout << "\n";
cout << "This is a do-while loop example \n";
bool finished;
do
{
cout << "Enter <1> to continue: ";
cin >> userChoice;
if (userChoice == 1)
{
finished = true;
}
else
{
finished = false;
}
} while (finished == false);
cout << "\n";
cout << "This is a for loop example \n";
int i,nCount,nStep;
cout << "Enter the number to count: ";
cin >> nCount;
cout << "Enter the step Size: ";
cin >> nStep;
for (i = 0; i <= nCount; i = i + nStep)
{
if (i < nCount)
{
cout << i << " and counting... \n";
}
else
{
cout << i << " and done. \n";
}
}
return 0;
}
{
cout << i << " and done. \n";
}
}
return 0;
}