This program involves a for loop as well. But only has to record the score of team a and b for each quarter for a total of 4 quarters. I get it to compile, just getting some really big numbers. Any suggestions?
// Lab0904.cpp -
// Created by Taft Sanders on 10/12/12
#include <iostream>
usingnamespace std;
int main( )
{
int scoreA;
int scoreB;
int teamA;
int teamB;
for (int quarter=1; quarter<=4; quarter++)
{
cout<< "What is the score of Team A: ";
cin>>teamA;
cout<< "What is the score of Team B: ";
cin>>teamB;
}
scoreA=scoreA+teamA;
scoreB=scoreB+teamB;
cout<< "Final Scores: "<<endl;
cout<< "Team A: "<< scoreA<<endl;
cout<< "Team B: "<< scoreB<<endl;
if (scoreA>scoreB)
{
cout<<"Team A won!"<<endl;
}
if (scoreA<scoreB)
{
cout<<"Team B won!"<<endl;
}
if (scoreA==scoreB)
{
cout<<"Both teams had the same score"<<endl;
}
system ("pause");
return 0;
}
What is the score of Team A: 25
What is the score of Team B: 20
What is the score of Team A: 22
What is the score of Team B: 24
What is the score of Team A: 20
What is the score of Team B: 31
What is the score of Team A: 29
What is the score of Team B: 28
Final Scores:
Team A: 1965596241
Team B: 2686820
Team A won!
Press any key to continue . . .
Ok I guess it just took a little longer playing and I would have figured it out. Thanks to anyone that may be working on this currently. I'll post the code for those that may care to critique my results.
// Lab0904.cpp -
// Created by Taft Sanders on 10/12/12
#include <iostream>
usingnamespace std;
int main( )
{
int scoreA=0;
int scoreB=0;
int teamA;
int teamB;
for (int quarter=1; quarter<=4; quarter++)
{
cout<< "What is the score of Team A: ";
cin>>teamA;
cout<< "What is the score of Team B: ";
cin>>teamB;
scoreA=scoreA+teamA;
scoreB=scoreB+teamB;
}
cout<< "Final Scores: "<<endl;
cout<< "Team A: "<< scoreA<<endl;
cout<< "Team B: "<< scoreB<<endl;
if (scoreA>scoreB)
{
cout<<"Team A won!"<<endl;
}
if (scoreA<scoreB)
{
cout<<"Team B won!"<<endl;
}
if (scoreA==scoreB)
{
cout<<"Both teams had the same score"<<endl;
}
system ("pause");
return 0;
}
What is the score of Team A: 25
What is the score of Team B: 20
What is the score of Team A: 22
What is the score of Team B: 24
What is the score of Team A: 20
What is the score of Team B: 31
What is the score of Team A: 29
What is the score of Team B: 28
Final Scores:
Team A: 96
Team B: 103
Team B won!
Press any key to continue . . .