Problem with for loop...

#include<iostream>//program that uses C++ standarded library string class
#include<iomanip>// parameterized stream manipulators
using namespace std;

int main()

{
// get the user input for the number of arrays need create an dynamic array.

int numOfStudents=0;



cout<<"Please enter the number of students: ";
cin>>numOfStudents;



string studentName[numOfStudents];
string studentGrade[numOfStudents];
double studentMark[numOfStudents];
int h;
double total =0;
double average =0;
double highGrade=0;
double lowGrade=100;
string Grade;
double mark=0.0;


for (int h =0;h< numOfStudents; ++h)
{
cout<<" Please enter the student name: ";
cin>>studentName[h];

cout<<" Please enter the student midterm mark: ";
cin>>studentMark[h];

total= total + studentMark[h];

if (h==0)
highGrade=studentMark[h];
lowGrade=studentMark[h];

if(highGrade<studentMark[h])
highGrade=studentMark[h];

if(lowGrade>studentMark[h])

lowGrade=studentMark[h];

}

for (not sure how use to apply this logic...)
Grade=studentGrade[h];

if (studentMark[h]>=(average+10))
cout<<"A"<<Grade;
if (studentMark[h]>=(average+5))
cout<<"B"<<Grade;
if (studentMark[h]>=(average-5))
cout<<"C"<<Grade;
if (studentMark[h]>=(average-10))
cout<<"D"<<Grade;
else
cout<<"F"<<Grade;
}

average = total/numOfStudents;
cout<< "Student Name "<<" Student Score "<<" Student Grade\n";

for (int h =0;h< numOfStudents; ++h)
{
cout<<" "<<studentName[h]<< " "<<studentMark[h]<< " "<<studentGrade[h]<<"\n";
}

cout<<"\nThe class average is: "<<average;

cout<< "\nThe number of students enrolled is: "<<numOfStudents<<"\n";

cout<<"\nThe minimum mark graded is: "<<lowGrade<<"\n";

cout<<"\nThe maximum mark graded is: "<<highGrade<<"\n";
system("pause");


}

I am having a problem with the "for loop"... for assigning a letter grade after program runs!


Last edited on
posting code without explaining what your having a problem with is not very helpful.
The following won't compile, your trying to create a static array with an expression that is not a constant value

string studentName[numOfStudents];

You need to change all your arrays to use pointers with dynamic memory.

string *studentName = new string [numOfStudents];

Topic archived. No new replies allowed.