+ 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!

17th Jul 2018, 12:11 PM
LetterC67
LetterC67 - avatar
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.
17th Jul 2018, 12:21 PM
Suraj Jha
Suraj Jha - avatar
+ 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".
19th Jul 2018, 10:04 AM
Suraj Jha
Suraj Jha - avatar
+ 3
hope you got an idea!
17th Jul 2018, 12:23 PM
Suraj Jha
Suraj Jha - avatar
17th Jul 2018, 12:33 PM
Yuri Biasi
Yuri Biasi - avatar
+ 1
Kashir what if user enter negative value!!
17th Jul 2018, 11:48 PM
Suraj Jha
Suraj Jha - avatar
+ 1
choose number such that it will way far than users imagination!!
17th Jul 2018, 11:48 PM
Suraj Jha
Suraj Jha - avatar
+ 1
Kashir first read what is asked... still if you don't understand then copy my code and run it.
18th Jul 2018, 12:28 AM
Suraj Jha
Suraj Jha - avatar
0
good ideA
17th Jul 2018, 7:22 PM
Kashir
Kashir - avatar
0
it is a excellent question
21st Jul 2018, 5:42 AM
deepak sharma
deepak sharma - avatar
- 5
int a =-23545; do { cout<<"\nplease enter a number"; cin>>a; cout<<a; } while(a>0)
17th Jul 2018, 7:24 PM
Kashir
Kashir - avatar
- 5
Suraj in your code if user enter value but not equal to number you enter then ? your code is wrong
18th Jul 2018, 12:04 AM
Kashir
Kashir - avatar