#include <iostream>
#include <string> //Needed to include string
usingnamespace std;
int main()
{
int nost = 0;
string names = " ";
int score[] = {NULL};
int num = 0;
int a;
double total = 0;
double average;
num = 0;
string grades[] = {NULL};
cout<<"How many students are there? : ";
cin >> nost;
cin.ignore(); // cin.ignore(); will make sure it dose not skip Enter name;
cout <<"Enter name : ";
getline(cin, names); /* When getting a string, use getline incase user input has spaces*/
cout<<"Enter a score : ";
cin >> score[num];
int minimum = score[num]; // initialize to first score.
int maximum = score[num]; // initialize to first score.
while(num < nost && score[num])
{
total += score[num];
++num;
if(num < nost)
{
cout<<"Enter a score: ";
cin>>score[num];
if (score[num] < minimum)
{
minimum = score[num];
}
if (score[num] > maximum)
{
maximum = score[num];
}
}
}
cout<< "The entered test scores are: ";
for (a = 0; a < num; ++a)
cout<<score[a]<<" ";
average = total / num;
cout<<endl<<"The average test score is "<<average<<endl;
cout<<"The highest score is "<<maximum<<" and the lowest score is "<<minimum<<endl;
system("PAUSE");
}
I don't think you can have variable arrays like that. The size of the array must be known at compile-time; that is, before the program actually runs. What you could do is create an array with 20 scores/names, since that's your max, and just fill the array until the user stops or you reach 20.
Since you don't initialize nost to any value, it has some random garbage data.
I don't think you can have variable arrays like that. The size of the array must be known at compile-time; that is, before the program actually runs. What you could do is create an array with 20 scores/names, since that's your max, and just fill the array until the user stops or you reach 20.
Since you don't initialize nost to any value, it has some random garbage data.