+ 5
Please help me
I want to print "enter a number".After that enter a number. if i dont enter anything and only press Enter. i want to print "enter a number" again!
11 ответов
+ 11
you can already initiate the variable with choosing any random value.. and use the conditional loop...
eg.
#include<iostream>
using namespace std;
int main(){
int a=137347985375;
do{
cout<<"\nEnter a number : ";
cin>>a;}while(a==137347985375);
return 0;
}
here I initiated the variable with 137347985375 if user won't enter any value the while statement will become true and it will again ask user to enter a value.
+ 6
🇻🇳GNAOH🇻🇳
you can also use this program if the data type of your variable is char.
#include<iostream>
using namespace std;
int main(){
char a;
do{
cout<<"\nEnter a number : ";
cin>>a;}while(a=='\r');
return 0;
}
here '\r' is a character for enter.
if it's data type is string use "\r".
+ 3
hope you got an idea!
+ 3
Take a look at this -> https://stackoverflow.com/questions/18728754/checking-input-value-is-an-integer
+ 1
Kashir what if user enter negative value!!
+ 1
choose number such that it will way far than users imagination!!
+ 1
Kashir first read what is asked... still if you don't understand then copy my code and run it.
0
good ideA
0
it is a excellent question
- 5
int a =-23545;
do {
cout<<"\nplease enter a number";
cin>>a;
cout<<a;
}
while(a>0)
- 5
Suraj in your code if user enter value but not equal to number you enter then ? your code is wrong