Too many error outputs

I was able to create this code, but when I tried to put in a sentence of 6 words, the command, std::cout << "An error has occured. Please enter 'help' for more." << std::endl; repeated itself 6 times. I only need it to repeat once. Any solutions?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <iostream>
#include <string>

int main()
{
    std::string input;
    do{
        std::cin >> input;
        if(input == "help")
        {
            std::cout << "------help---menu------" << std:: endl;
            std::cout << "quit - quits the program" << std::endl;
        }
        else
        {
        std::cout << "An error has occured. Please enter 'help' for more." << std::endl;
        }
    }
    while(input != "quit");
}
Last edited on
use getline instead of >>input. >> works off whitespace, so spaces make a 6 word entry look like 6 entries. getline works of lines, so a 6 word entry looks like 1 entry. If you need to mix >> and getline, look up how to do that properly or you may get some problems.
Last edited on
Yeah, I figured it out before. Thank you for your assistance anyway, jonnin. I appreciate it.
Topic archived. No new replies allowed.