In the code below the first thing the program will do is ask the user their Username. I have an IF statement just after that to determine if the user has left it blank, and if so to have it exit the program, otherwise jumps to another function. The problem is that when I test it and dont enter any user data, then hit enter, it just jumps the cursor to the next line, and will skip a line each time I hit enter. For learning/testing purposes I want it to just exit when they type no name and hit enter, instead of just jumping down a line until they finally do enter something, and press enter. Thanks folks.
Because once the function getName has finished it's task of "getting the users name" I want it to move onto guessNumber where I'll have the code for the actual number guessing game. Is this not good practice? Should my program not be broken up into separate functions to handle separate tasks instead of cramming it all into the main function?
EDIT: I guess it doesnt need to call guessNumber as it's already assigned to in the main function, right?
"getline" retrieves the entire line of input until a newline character is reached (it does not skip whitespace like "cin" does).
1 2
string myString;
getline(cin, myString);
If the user enters multiple words, this will capture all of them. If you want to do something based on what the user entered, you will have to parse this string and break it up.