I updated the program to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <iomanip>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
using namespace std;
//Main Function
int main()
{
ifstream file;
const int MAX_ARRAY_SIZE = 47;
string wteam;
string lteam;
float TempScore;
int sum = 0;
int counter=0;
int high;
int low;
double teamsaboveforty;
float totalaverage;
file.open("superbowl.dat");
string winningteam [MAX_ARRAY_SIZE];
string losingteam [MAX_ARRAY_SIZE];
float score [MAX_ARRAY_SIZE];
cout << left;
cout << setw(15) << "Winning Team" << setw(15) << "Losing Team" << setw(15) << "Score" << endl;
cout << setw(45) << "=====================================================================" << endl;
while (file>>wteam>>lteam>>TempScore)
{
file>>wteam>>lteam>>TempScore;
winningteam[counter]=wteam;
losingteam [counter]=lteam;
score [counter]=TempScore;
cout<< left;
cout << setprecision(0)<< fixed;
cout << setw(15) << wteam << setw(15) << lteam << setw(15) << TempScore << endl;
counter++;
}
for (int i=0; i<47; i ++)
{
sum = sum + score[i];
}
totalaverage = sum /47;
high = 0;
for (int i = 0; i<47; i++)
{
if (score[i]> score[high])
{
high = i;
}
}
low = 0;
for(int i = 0; i<47;i++)
{
if(score[i] < score[low])
{
low = i;
}
}
cout << "Winning teams scored " << totalaverage << " points on average." << endl;
cout << endl;
cout << "There are " << teamsaboveforty << " teams that scored above 40." << endl;
cout << endl;
cout << setw(15) << "Highest Points:" << setw(10) << wteam << setw(10) << lteam << score[high] << endl;
cout << setw(15) << "Lowest Points:" << setw(10) << wteam << setw(10) << lteam << score[low] << endl;
file.close();
return 0;
}
|
The printed output is given as:
Winning Team Losing Team Score
=====================================================================
Packers Raiders 33
Chiefs Vikings 23
Cowboys Dolphins 24
Dolphins Vikings 24
Steelers Cowboys 21
Cowboys Broncos 27
Steelers Rams 31
49ers Bengals 26
Raiders Redskings 38
Bears Patriots 46
Redskins Broncos 42
49ers Broncos 55
Redskins Bills 37
Cowboys Bills 30
Cowboys Steelers 27
Broncos Packers 31
Rams Titans 23
Patriots Rams 20
Patriots Panthers 32
Steelers Seahawks 21
Giants Patriots 17
Saints Colts 31
Giants Patriots 21
Ravens 49ers 34
Winning teams scored 15 points on average.
There are 0 teams that scored above 40.
Highest Points:Ravens 49ers 55
Lowest Points: Ravens 49ers -0
1. For some reason it won't read all the data for all 47 superbowls...it is skipping over every other...
I understand that this is what's causing my totalaverage to be set to 15, which is incorrect.
2. The program is only using the last of the teams (Ravens and 49ers) for the Highest and Lowest points outputs, as well as an incorrect Lowest Points output for the value
3. I'm also not sure what to do about the teamsaboveforty part of the array....
I felt pretty confident after your reply, but I think now I'm lost again..