Ask Question
15 January, 22:16

ProcessName2

Modify your solution to the previous ProcessName exercise so that it re-prompts until the user types a name that is at least 5 letters total in length and has at least one space in it. '

Type your name: Joe

Error, must be at least 5 chars with a space.

Type your name: O K!

Error, must be at least 5 chars with a space.

Type your name: what

Error, must be at least 5 chars with a space.

Type your name: Tyler Durden

Your name is: Durden, T.

+2
Answers (1)
  1. 15 January, 23:03
    0
    This is easily solvable with a for loop. Something like:

    (I assume c++)

    #include

    #include

    int main () {

    take_input: / /tag

    std::string input;

    cin >> input; / /take the input

    int spaceCount = 0;

    char checking;

    for (unsigned int i = 0; i = = input. length (); + +i) {

    checking = spaceCount[i];

    if (checking = = ' ')

    spaceCount++;

    }

    if (spaceCount > = 1 && input. length > = 5)

    std::cout << "Your name is " + input;

    else

    goto take_input; / / reasks for input if the conditions are not met

    return 0;

    };

    **remove all spaces before using the code, the if statements are messed up
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “ProcessName2 Modify your solution to the previous ProcessName exercise so that it re-prompts until the user types a name that is at least 5 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers