0

so I'm using the nfl stats below in my program. i have the program reading in the file fine. I will be doing three different analysis to these stats one will be adding all the yards of every team and converting them into miles, the other will just be adding all the passing yards from every team and reporting the sum, and the last analysis will be sorting out which number is the highest out of all the points for every team and reporting it.

I'm having trouble my value keeps coming up to 2750 when i add all the numbers in the yards array giving me an answer of 1.59144 when i know it's way more then that obviously! i will post the code hopefully someone will help me out! thanks.

RK      TEAM    YDS YDS/G   PASS    P YDS/G RUSH    R YDS/G PTS PTS/G
1   Philadelphia    4951    412.6   3066    255.5   1885    157.1   271 22.6
2   New Orleans 4946    449.6   3566    324.2   1380    125.5   362 32.9
3   New England 4724    429.5   3510    319.1   1214    110.4   331 30.1
4   Green Bay   4414    401.3   3345    304.1   1069    97.2    382 34.7
5   Carolina    4386    398.7   2898    263.5   1488    135.3   252 22.9
6   Dallas      4291    390.1   2988    271.6   1303    118.5   270 24.5
7   San Diego   4246    386.0   3037    276.1   1209    109.9   249 22.6
8   Houston     4177    379.7   2508    228.0   1669    151.7   293 26.6
9   Detroit     4144    376.7   2997    272.5   1147    104.3   316 28.7
10  Pittsburgh  4120    374.5   2914    264.9   1206    109.6   233 21.2
11  NY Giants   4111    373.7   3206    291.5   905 82.3    252 22.9
12  Oakland     4106    373.3   2465    224.1   1641    149.2   260 23.6
13  Atlanta     4025    365.9   2730    248.2   1295    117.7   259 23.5
14  Buffalo     3800    345.5   2458    223.5   1342    122.0   261 23.7
15  Tampa Bay   3742    340.2   2624    238.5   1118    101.6   199 18.1
16  Chicago     3729    339.0   2389    217.2   1340    121.8   288 26.2
17  Baltimore   3692    335.6   2604    236.7   1088    98.9    272 24.7
18  Cincinnati  3681    334.6   2488    226.2   1193    108.5   259 23.5
19  Seattle     3582    298.5   2333    194.4   1249    104.1   216 18.0
20  Washington  3546    322.4   2596    236.0   950 86.4    183 16.6
21  Tennessee   3515    319.5   2540    230.9   975 88.6    226 20.5
22  Miami       3480    316.4   2268    206.2   1212    110.2   212 19.3
23  Arizona     3473    315.7   2270    206.4   1203    109.4   213 19.4
24  Minnesota   3464    314.9   1969    179.0   1495    135.9   214 19.5
25  NY Jets     3463    314.8   2359    214.5   1104    100.4   256 23.3
26  Denver      3441    312.8   1684    153.1   1757    159.7   221 20.1
27  San Francisco   3395    308.6   1979    179.9   1416    128.7   262 23.8
28  Kansas City 3346    304.2   2011    182.8   1335    121.4   153 13.9
29  Cleveland   3255    295.9   2190    199.1   1065    96.8    165 15.0
30  St. Louis   3251    295.5   2099    190.8   1152    104.7   140 12.7
31  Indianapolis    3080    280.0   1991    181.0   1089    99.0    150 13.6
32  Jacksonville    2750    250.0   1444    131.3   1306    118.7   138 12.5

Functions.cpp

#include <iostream>
#include <fstream>
#include<string>
#include"functions.h"
#include<iomanip>
#define FILE_IN "nflstats.txt"//name of my file
using namespace std;

//passing in team array, yards array, passyards and points array.

float readFile(string teams[], float yards[], float passyards[], float points[])
{
    int i = 0;
    //getting rid of first line since i will not use
       string trash;

        //trashing columns i will not use so i can display on console.

        float ftrash1, ftrash2, ftrash3,ftrash4,ftrash5;
    float sum =0.,miles =0.;

    ifstream input;

    input.open(FILE_IN);

    if(!input)
    {
        cout<<"\n Can't find input file " << FILE_IN;
        cout<<"\n Exiting program, bye bye \n ";
        exit(1);
    }


    getline(input,trash);

    while(!input.eof())

    {
    input>>trash;
    input.ignore();
    getline(input,teams[i],'\t'); //reading team names

    input>>yards[i]>>ftrash1>>passyards[i]>>ftrash2>>ftrash3>>ftrash4>>points[i]>>ftrash5;
    input.ignore();

    //couting to console
    cout<<teams[i]<<"\t"<<yards[i]<<"\t"<<ftrash1<<"\t"<<passyards[i]<<"\t"<<ftrash2<<"\t"<<ftrash3<<"\t"<<ftrash4<<"\t"<<points[i]<<"\t"<<ftrash5<<"\n";

    }


}
void AnalyzeStats(float yards[], float passyards[], float points[])
{
    double sum=0.;
    double miles=0.;
    for(int i=0;i<31;i++)
    {                                   //THIS IS WHERE IM HAVING THE PROBLEM
        sum+=yards[i];              //SUM IS COMING OUT TO 2750 WHEN
    }                                   //THE SUM IS WAY MORE THEN THAT!
    miles=sum/1728;

    cout<<miles;

}

void writeOutput()
{
    //not finished

}

Driver.cpp

#include <iostream>
#include <fstream>
#include<string>
#include "functions.h"

using namespace std;

int main()
{
    string teams[31];
    float yards[31], passyards[31], points[31];
    for(int i = 0; i<31; i++)
    {
        yards[i]=0;
        passyards[i]=0;
        points[i]=0;
    }




    readFile (teams, yards, passyards, points);
    AnalyzeStats(yards, passyards, points);
    writeOutput();

return 0;
}

Functions.h

using namespace std;
float readFile(string teams[], float yards[], float passyards[], float points[]);
void AnalyzeStats(float yards[], float passyards[], float points[]);
void writeOutput();

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Ancient Dragon
0

The loop starting on line 38 never increments the i counter, causing everything to be read into the same element of all the arrays.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.