Null statement on switch case and if and else statement

im currently having problem of using null statement on my switch case by using the if and else statement. Pls help me.

switch (o)
{
case '1':

cout << "Please enter the detail of the ownership.";
cout << endl <<"Please enter name your name : ";
cin >> name;
if (name == null){
cout << "Please try again" << endl;
}
Last edited on
im trying to make the user, if the user did not enter the name, it will pop an error
What type is name?
string type for the name
If you want to specifically read blank input as something to detect, then you need to use something like

getline(cin,name);

But beware of mixing >> and getline().
You might need to look up cin.ignore() as well.
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/

HINT: you can edit your post and add the tags.

Well, you should have your name retrieval code in a loop block, while or do-while, so the data entry repeats when the user enters a "bad" name.
http://www.cplusplus.com/doc/tutorial/control/
Last edited on
strings do not equal null in c++.
an empty string in c++ is "" or length = 0.

null can mean something for C strings but it is very complicated, as you can use null == 0 exploit or you could actually have a null pointer depending on what the coder did to you.
Last edited on
hmm i have done the getline part but if i wan to use it as a float(decimal) how should i do it?
Topic archived. No new replies allowed.