-
Help with wierd error
I've been told to make a program that takes in the data for 3 soccer players throughout 10 games. when i run it so far (i havent made the print function yet) it asks for the name of the player, then enters the nested loop and never stops for input (at any of the "cin >>" spots) any ideas as to why?
Code:
#include <iostream.h>
int main ()
{
int names[3];
int shots[10];
int shotsongoal[10];
int goals[10];
for (int i=1; i<=3; i++)
{
cout << "Player " << i << "'s name: " << endl;
cin >> names[i];
for (int x=1; x<=10; x++)
{
cout << "Game " << x << endl;
cout << "Shots: \n";
cin >> shots[x];
cout << "Shots on Goal: \n";
cin >> shotsongoal[x];
cout << "Goals: \n";
cin >> goals[x];
}
}
system("PAUSE");
return 0;
}
-
It's because you are entering string (character) data into names[i], but names is an int array;
I would suggest you use std::string names[3];
be sure to include <string>
-
-
one other thing I should had mentioned, unless you are using an old comipler or have some other compelling reason, you really should be using <iostream> and not <iostream.h>