for some reason I cannot add integers in an array of structures. here is the code.
#include<iostream>
#include<iomanip>
using namespace std;
const int SIZE = 5;
struct playerInfo {
char name[30]; //Players name
int number;
int points;
};
int main()
{
int total = 0; // to hold total points scored
playerInfo player[SIZE];
cout << "Enter the information for five players:\n\n";
for (int i = 0; i < SIZE; i++)
{
cout << "Player " << i+1 << " info\n";
cout << "Enter the name of the player :";
cin >> player[i].name;
cout << "Enter the players number :";
cin >> player[i].number;
cout << "Enter the players points :";
cin >> player[i].points;
cout << "------------------------------\n";
}
//calculate total
for (int i = 0; 0 < SIZE; i++)
{
total = (player[i].points + total);
}
//showResult
cout << "Here is a list of players and thier scores\n";
cout << "------------------------------------------\n";
for (int i = 0; i < SIZE; i++)
{
cout << player[i].name << "\tPoints:" << player[i].number << "\tScore:" << player[i].points << endl;
}
cout << "The total points scord by the team is :" << total << endl;
return 0;
}
If I comment this out
//calculate total
for (int i = 0; 0 < SIZE; i++)
{
total = (player[i].points + total);
}
the program will run fine without giving me the total obviosly. This code crashes the program...
I also tried
total += player[i].points
with no luck.
any help would be great!
Cheers