Hi, I'm a new programmer trying to write a baseball code for my brother. I'm trying to get it so that when you enter the name of the player, their batting average for the 2014 season shows up. Sounds simple, right? For some reason, the string isn't working. I'm sure it's a simple solution that I just don't understand.
This is my code thus far, and I plan to have all the names of the players for the SF Giants in the code eventually:
#include <string>
using namespace std;
int main ()
{
int avgvalue;
string name;
string "Buster Posey", "Brandon Belt", "Joe Panik", "Brandon Crawford", "Pablo Sandoval", "Mike Morse", "Angel Pagan", "Hunter Pence";
cout << "Please enter the name of an SF ballplayer\n" << "who played during the 2014 season." << endl;
getline (cin, name);
if (name == "Buster Posey")
avgvalue = .311;
else if (name == "Brandon Belt")
avgvalue = .243;
else if (name == "Joe Panik")
avgvalue = .305;
else if (name == "Brandon Crawford")
avgvalue = .246;
else if (name == "Pablo Sandoval")
avgvalue = .279;
else if (name == "Mike Morse")
avgvalue = .279;
else if (name == "Angel Pagan")
avgvalue = .300;
else if (name == "Hunter Pence")
avgvalue = .277;
else
cout << "This name is not recognized. Please rerun the program and try again." << endl;
cout << name <<"'s batting average in the 2014 season\n" << "was " << avgvalue << "." << endl;