Player Efficiency Rating program problem

I'm currently trying to write a program to find an NBA players PER. Whenever I try to get the players different stats, the program won't let me input any information.
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
  #include <iostream>
using namespace std;

int main()
{

	string player[50];
	float uPER, MP, threeP, AST, factor, teamAST, teamFG, FG, FT, VOP, TOV, DRB, FGA, FTA, TRB, ORB, STL, BLK, PF, lgFT, lgPF, lgFTA, lgAST, lgFG, lgPTS, lgFGA, lgORB, lgTOV, lgTRB;

	cout << "This program calculates NBA players PER, or Player Efficiency Rating." << endl;
	cout << "Player's name? ";
	cin >> player[50];

	cout << "Enter " << player[50] << " per game stats when prompted." << endl;

	cout << "Minutes Played: ";
	cin >> MP;
	cout << endl;

	cout << "Three Pointers: ";
	cin >> threeP;
	cout << endl;

	cout << "Assists: ";
	cin >> AST;
	cout << endl;

	cout << "Team Assists: ";
	cin >> teamAST;
	cout << endl;

	cout << "Team Field Goals: ";
	cin >> teamFG;
	cout << endl;

	cout << "Field Goals: ";
	cin >> FG;
	cout << endl;

	cout << "Free Throws: ";
	cin >> FT;
	cout << endl;

	cout << "Turnovers: ";
	cin >> TOV;
	cout << endl;

	cout << "Field Goals Attempted: ";
	cin >> FGA;
	cout << endl;

	cout << "Free Throws Attempted: ";
	cin >> FTA;
	cout << endl;

	cout << "Total Rebounds: ";
	cin >> TRB;
	cout << endl;

	cout << "Offensive Rebounds: ";
	cin >> ORB;
	cout << endl;

	cout << "Steals: ";
	cin >> STL;
	cout << endl;

	cout << "BLocks: ";
	cin >> BLK;
	cout << endl;

	cout << "Personal Fouls: ";
	cin >> PF;
	cout << endl;

	cout << "League Average for the next stats.";
	cout << endl;

	cout << "Free Throws: ";
	cin >> lgFT;
	cout << endl;

	cout << "Personal Fouls: ";
	cin >> lgPF;
	cout << endl;

	cout << "Free Throws Attempted: ";
	cin >> lgFTA;
	cout << endl;

	cout << "Assists: ";
	cin >> lgAST;
	cout << endl;

	cout << "Field Goals: ";
	cin >> lgFG;
	cout << endl;

	cout << "Points: ";
	cin >> lgPTS;
	cout << endl;

	cout << "Field Goals Attempted: ";
	cin >> lgFGA;
	cout << endl;

	cout << "Offensive Rebounds: ";
	cin >> lgORB;
	cout << endl;

	cout << "Turnovers: ";
	cin >> lgTOV;
	cout << endl;

	cout << "Total Rebounds: ";
	cin >> lgTRB;
	cout << endl;

	factor = (2 / 3) - (0.5 * (lgAST / lgFG)) / (2 * (lgFG / lgFT));

	VOP    = lgPTS / (lgFGA - lgORB + lgTOV + 0.44 * lgFTA);

	DRB   = (lgTRB - lgORB) / lgTRB;

	cout << factor << " , " << VOP << " , " << DRB;
}
I'm not sure why you have an array of strings. I think you meant to do an array of chars or even just a string(which I would suggest.) Also arrays start at index 0 so the last element would be 49 not 50.

Also when ever you have to repeat something like you are it is best to use a function and then just call that a few times or even just use a loop. I'll simplify your code for you so you can get the picture.


ex:
1
2
3
4
5
6
7
8
9
10
11
int main()
{
    const int SIZE( 3 );
    const std::string types[ SIZE ]{ "Name: " , "Turnovers: " , "Total Rebounds: " };
    double values[ SIZE ]{ 0.0 };
    for( int i( 0 ); i < SIZE; ++i )
    {
         std::cout << types[ i ] << std::flush;
         std::cin >> values[ i ];
    }
}


You might have to initialize your arrays and ints differnelty if you do not have c++11 enabled. The c++98 way is like this
1
2
const int SIZE = 3;
double values[ 3 ] = { 0.0 };


I would also recommend a vector for storing the values.
1
2
3
4
5
6
7
8
9
10
#include <vector>

std::vector<double> values( 0 ); //The ( 0 ) is for setting the size you don't technically need it.

for( auto i( 0 ); i < SIZE; ++i ) //auto gets the type automatically. I was lazy
{
    std::cout << "enter something: " << std::flush;
    std::cin >> temp_value;
    values.push_back( temp_value );
}
Topic archived. No new replies allowed.