[Solved] C++: While Looping Amount of Times


this is a suitable time to utilize the

do while

loop

the way it works is it will execute the statement within the block without evaluating any conditions and then evaluate the condition to determine if the loop should run again

this is what your program could look like

#include <iostream>
using namespace std;

int main(void)
{
int counter = 0, num;
do
{
if (counter > 10) // or >=10 if you want to display if it is 10
{
cout << "exiting the loop!" << endl;
break; // the break statement will just break out of the loop
}
cout << "please enter a number not equal to 5" << endl;
cin >> num;
counter++; // or ++counter doesn't matter in this context

}
while ( num != 5);
return 0;
} 

solved C++: While Looping Amount of Times