Hello. In my C++ class we are now in the chapter of loops and I have began to start getting lost. I have been doing fine until now, and now starting to get worried.
Last chapter we had to write a program that ask the user to enter a number and told them if it was even or odd. This chapter the instructor has told us to modify the program and use a while loop so that the program loops a total of 3 times.
The program is here
I am very confused on how to use a loop. We went over the formats of the while loop and what they do but never used one in a actually program. I'm really even sure where to put the loop. Do I put it underneath the if statements or erase the if statements and use the loop here.Code:#include <iostream> using namespace std; int main() { int number; cout << "Enter an integer: "; cin >> number; if (number % 2 == 0) cout << number << " is even." << endl; if (number % 2 != 0) cout << number << " is odd." << endl; return 0; }
I know the format of a while loop is:
while (expression)
{
statement;
}
However, I am not sure how to fully use it. If someone could explain or show me how to use a while loop for this program so that it loops 3 times, I would greatly appreciate it.