Newbie c++ programmer! helppp

Create a new .cpp program that reads the data from footballstats.txt (under Resourses-Examples) using a while-loop. Your program will use a counting loop to (a) determine what type of player a data row indicates, and (b) determine the average weight of those player types and all the players listed in the text file.

As the program reads the data from the file, it must determine if the player is a lineman, a back, or other. (You will use an if...else if...else block to do this.) To determine the type of player a data entry represents, assume that all numbers between 1 and 49 are backs, between 50 and 79 are linemen, and between 80 and 99 are other types. Use counters to keep track of the number of each type of player (using the ++ operator), and use other variables to determine the total weight of each type of player (use the += compound operator). When you reach the end of the file, stop the while loop (use a counting option for this program, and stop after reading the 20 lines in the file). When all the data has been read, calculate the average weight of each group of player types, and then the average weight of the entire team. Print the results to both the screen and to a file named yourname_average_weight.txt, with appropriate labels.

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
  using namespace std;
#include<iostream>
#include<fstream>
#include<iomanip>
int main()
{
    int sentinel, jersey_no;
    double weight, total_weight,avg_weight;
    ifstream datain ( "footballstats.txt");
    sentinel = 999;
    total_weight = 0;
    cout << "     Jersey No:       Weight: " << endl;
    datain >> jersey_no;
  while (jersey_no != sentinel)
      {
      datain >> weight;
      cout <<setw(11)<< jersey_no<<setw(16)<<weight<<endl;
      total_weight = weight + total_weight;
      avg_weight= total_weight/20;
      datain >> jersey_no;
      if (jersey_no<1)
      }
    cout << endl << "Total Weight = " << total_weight << endl << endl;  
    cout << endl << "Average Weight = " << avg_weight << endl << endl;  
    
 /*   if (jersey_no >1 && jersey_no< 49)
    {
     while (jersey_no != sentinel)
      {
      datain >> weight;
      cout <<setw(11)<< jersey_no<<setw(16)<<weight<<endl;
      total_weight = weight + total_weight;
      avg_weight= total_weight/20;
      datain >> jersey_no;
      }
    }*/
    

return 0;
}
What's your problem?

using namespace std;

needs to be after your #include s.

For the output to a file, you need to use an fstream.

Your teacher said to use the += operator did he/she not?

So why:
total_weight = weight + total_weight;?
Do you not fully understand the assignment?
I am not sure what you need.
Last edited on
Topic archived. No new replies allowed.