-3

Once the program gets to the if statement it just ignores it and stops. Xcode says that there are no errors so i have no clue what is going on.

#include <iostream>
#include <string>

int main()
{
    std::string team;
    std::cout << "Welcome to The Baseball game!\n" << std::endl;
    std::cout << "choose a team.\n";
    std::cin >> team;

    if (team == "Arizona Diamondbacks") //this is were it stops working
    {
        std::cout << "You chose the Arizona Diamondbacks, here is your lineup:" << std::endl << "1. RF Gerrardo Parra" << std::endl << "2. 2B Willie Bloomquist" << std::endl << "3. 1B Paul Goldschmidt" << std::endl << "4. C Miguel Montero" << std::endl << "5. LF Jason Kubel" << std::endl << "6. CF A.J. Pollock" << std::endl << "7. SS Didi Gregorius" << std::endl << "8. 3B Cliff Pennington" << std::endl << "9. SP Patrick Corbin" << std::endl << "your starting pitcher will be Patrick Corbin.\n";
    }
    if (team == "Atlanta Braves")
    {
        std::cout << "you chose the Atlanta Braves";
    }
    return 0;
}

3 Answers3

2
std::cin >> team;

This reads one word. If you enter "Arizona Diamondbacks", team gets set to "Arizona". You can use getline instead to read a whole line of input:

std::getline(std::cin, team);
2

The ifstream extraction operator >> for a std::string extracts whitespace-delimited strings. So your cin >> team is stopping at the first space/tab in the users input. You'll need to use a function that reads the entire line instead.

twalberg
  • 59,951
  • 11
  • 89
  • 84
1

I think its problem with your cin >> team; that you are using to get string input. Try using getline

cin stops input when space character appears.

Shumail
  • 3,103
  • 4
  • 28
  • 35