0

I'm having a problem here.

I want my program to print different texts depending on the user input.

std::string username;

void whoareyou()
{
    std::cout << "Name: " << std::flush;
    std::cin >> username;

  if (username == "Jack", "jack", "jak")
  {
     std::cout << "Hello jack, how are you?" << std::endl;
  }
  else if (username == "Bob", "bob", "bbob")
  {
    std::cout << "Hello Bob, how are you?" << std::endl;
  }
  else
  {
    std::cout << "I don't know you, bye." << std::endl;
  }
}    

Every time I input bob's code the program runs jack's. How do I fix this? I plan to add more users to this.

Thank you in advance.

iphonic
  • 12,615
  • 7
  • 60
  • 107
  • 3
    Your problem is that you haven't (apparently) bothered to [read a good beginners book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) or learn the language. – Some programmer dude Apr 14 '17 at 05:57

3 Answers3

0

use the or || operator in all the if statements like this:

if(username == "jack" || username == "Jack" || username == "jak")


else if(username == "Bob" || username == "bob" || username == "bbob")
msfs
  • 11
  • 2
0

You need

if (username == "Jack" ||  username == "jack" || username =="jak")

instead of

if (username == "Jack", "jack", "jak")

and other if statements.

kvorobiev
  • 5,012
  • 4
  • 29
  • 35
0
std::string username;

void whoareyou() {
    std::cout << "Name: " << std::flush;
    std::cin >> username;
    if (username == "Jack" || username == "jack" || username == "jak") {
         std::cout << "Hello jack, how are you?" << std::endl;
    }
    else if (username == "Bob" || username == "bob" || username == "bbob") {
         std::cout << "Hello Bob, how are you?" << std::endl;
    }
    else {
         std::cout << "I don't know you, bye." << std::endl;
    }
}
ShahzadIftikhar
  • 515
  • 2
  • 11