0
How to code a loop that keep asking user to input until the user input a correct number ?
5 Respuestas
+ 3
while ( 1 )
{
cin>>num;
if ( num == correct_num )
break;
}
here correct_num is variable on which the correct value is assigned already
+ 2
do{
// ask for input: cin>>input;
} while(input ! = correctInput);
+ 1
It is wrong. the cin>>num; needs to be in the do while loop.
0
#include <iostream>
using namespace std;
int main()
{
int num;
cin>>num;
do {
cout<<"enter again";
} while(num != num);
return 0;
}
correct me if this is wrong. thanks
0
And the num != num is wrong too. the second num needs to be an other variabele or a value.