cout << "Enter the team you'd like results for.\n";
cin >> team;
cout << "File open failure!\n";
string s1, s2, s3, s4;
int score1, score2;
while (inFile >> s1 >> s2 >> s3 >> s4)
if (s2 == team)
elseif (s4 == team)
cout << s1 << s2 << s3 << s4 << endl;
My main question right now is with the if/else statement. With s1 and s3 being integers in the file, they need to be converted to int variables so they can be printed on the screen. I've read about stringstream and "#include <sstream> on various searches but it's not something that has been covered in class which typically means we can't use it. So I guess I need some ideas on what else I can use and maybe some reading I might need to look at. After staring at this for two days and getting nowhere any help is appreciated. I have no idea where to begin with this.
I actually used atoi instead and set score1 = atoi("s1") and score2 = atoi("s3") just before the while loop. It functions... albeit very poorly. It now prints the games for each team you type in but there's no spaces between the first score and the last team.
Here's my updated code and I've got it print the results for the team searched by the user. The next part I have to do is count the number of wins and losses. Currently my counters aren't working and all it does is print " team has 0 wins and 0 losses"
My guess is that this has to do with my atoi conversion but I really have no idea. Any thoughts on how I should go about trying to fix this?
The above code sets score1 to 0 since "s1" isn't a valid integer, (and it has no relationship whatsoever with the variable s1 on the previous line).
The correct code would look a bit more like this:
int score1 = atoi(s1.c_str());
This time, the actual contents of the variable s1 will be used correctly. But - the result will still be zero. Why? because s1 is an empty string. The conversion using atoi() needs to be done at the correct sequence in the program, after string s1 has been assigned a proper value.