+ 2
How can I make a program not to view next contents of the program if the user as not enter his/her name?
Have made a simple program in C++.. That request a user to enter his name. I want the program not to go to the step or to view next contents of the the program regardless the user not entering his/her name..
7 ответов
+ 8
Coder C++
I would recommend that you use the following if statement:
if (name != "" && name != " " && name != "1" && name != "2" && name != "3" && name != "4" && name != "5" && name != "6" && name != "7" && name != "8" && name != "9" && name != "0") {
cout << "Welcome," << name << "!";
}
--
I know, it is not the best, but once you are completely familiar to functions, you can put that whole block of code in its own function.
+ 2
string name{};
cout<<"Register you name: ";
do {
getline(cin,name);
} while(name == "");
+ 1
use loop and *if-else statement for checking whether string is empty or not*
+ 1
Edwin Pratt the program can still run whenever a user enters anything though an integer
0
Anna have tried that.. Still not getting it right... Help out