Assign element of array into string

Making program that reads data from a fancy text file, calculates qb ratings, then outputs everything in a fancy way.


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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <cmath> 
using namespace std;

string filename;
char teamABV[4], fullName[21];
string nameArray[50], qualNames[50], highPlayer;
float completions, attempts, yards, touchdowns, interceptions,
     compPercent, ypAttempt, tdpAttempt, ipAttempt, qbRating, totalRating,
      averageRating, qualAVG, qbArray[100], highRate, qualQBs[100],
      qtotalRating;
      
int i = 0, size = 0, qsize = 0, q = 0;
const int playerList = 50;

int main()
{
    cout << "This program will calculate the average passer rating based " << endl;
    cout << "on data from a text file." << endl;
    
    cout << "Please enter your full file's path." << endl;
    cin >> filename;//Get file name for user input
    
    ifstream qbinfo;
    qbinfo.open(filename.c_str());//Open input file
    
    while (qbinfo.fail())//In case of error
    {
        cout << filename << " is an incorrect input. " << endl;
        cout << "Please reenter your full file name and path." << endl;//Re-do
        cin >> filename;
        qbinfo.open(filename.c_str());
        
    }//end while         
           
    cout << "QB Name"
         << setw(20) << "Team"
         << setw(10)  << "Rating" << endl;//form table columns
           
           
           
               while ( qbinfo.get(fullName, 21)
                &&  qbinfo.get(teamABV, 4)
                && (qbinfo >> completions >> attempts >> yards >> touchdowns >> interceptions))
             {
                    qbinfo.ignore(1000, '\n');  // get rid of the trailing newline.
                
                    /*cout << completions   << " "
                         << attempts      << " "
                         << yards         << " "
                         << touchdowns    << " "
                         << interceptions << endl;
                     */      
                    
                        compPercent = ((completions / attempts) * 100 - 30)/20;
                        //cout << compPercent << endl;//get completion percent for loop
                            if (compPercent > 2.375)
                                compPercent = 2.375;
                            else if (compPercent < 0)
                                compPercent = 0;
                    
                        ypAttempt = ((yards/ attempts) - 3 ) * 1/4;
                        //cout << ypAttempt << endl;//get yards per attempt for loop
                            if (ypAttempt > 2.375)
                                ypAttempt = 2.375;
                            else if (ypAttempt < 0)
                                ypAttempt = 0;
                
                        tdpAttempt = (touchdowns / attempts) * 20;
                        //cout << tdpAttempt << endl;//get touchdowns per attempt for loop
                            if (tdpAttempt > 2.375)
                                tdpAttempt = 2.375;
                            else if (tdpAttempt < 0)
                                tdpAttempt = 0;
                
                        ipAttempt = 2.375 - ((interceptions / attempts ) * 25);
                        //cout << ipAttempt << endl;//get interceptions per attempt for loop
                            if (ipAttempt > 2.375)
                                ipAttempt = 2.375;
                            else if (ipAttempt < 0)
                                ipAttempt = 0;
                
                qbRating = ((compPercent + ypAttempt + tdpAttempt + ipAttempt) / 6 ) * 100;
                //cout << qbRating << endl;//output qb rating and name for loop
                
                
                
                cout << fullName << setw (6) << teamABV << setw(10) << qbRating << endl;
                
                if (attempts >= 224)
                    {
                        qualQBs[q] = qbRating;
                        qualNames[q] = fullName;
                        qsize++;
                        q++;
                    }//create arrays for qualified characters
                        
                
                nameArray[i] = fullName;
                qbArray[i] = qbRating; 
                i++;
                size++;


                
                
        }//end while()

    for (i = 0; i < size; i++)
        totalRating += qbArray[i];//total sum of all ratings
        
    averageRating = totalRating / size;//average rating for ALL players
    
    highRate = qualQBs[0];

    for (i = 0; i < size; i++)
    {
        if (qualQBs[i] > highRate)
            {
                highRate = qualQBs[i];
                highPlayer = qualNames[i];
            }
            
    }//Find highest rating of qualified players{

    for (i = 0; i < qsize; i++)
        qtotalRating += qualQBs[i];//total rating of all qualified players
    
    qualAVG = qtotalRating / qsize;//average for QUALIFIED players
    
    cout << "Summary: " << endl;
    cout << "Highest rating of qualified player: " << highRate << endl;
    cout << "Name: " << highPlayer << endl;
    cout << "Average rating of all players: " << averageRating << endl;
    cout << "Average rating of qualified players (224 attempts): " << qualAVG << endl;
    
    
    
    
    
    
    
    qbinfo.close();
    system("pause");
    
}

My problem now is in the lines
1
2
3
4
5
6
7
8
9
for (i = 0; i < size; i++)
    {
        if (qualQBs[i] > highRate)
            {
                highRate = qualQBs[i];
                highPlayer = qualNames[i];
            }
            
    }//Find highest rating of qualified players 


For some reason, when I go to output the name of the highest qualified player, the highPlayer outputs blank space. The code seems to be finding the right highRate value, but it doesn't copy anything to highPlayer! Help please?
Topic archived. No new replies allowed.