Question #283049


The program below computes the grade of five students based on the marks scored. Study it carefully, identify the different errors the program has, correct the errors and hence re-write the program so that it can run successfully without errors.



Expert's answer

#include<iostream>
#include<string>

using namespace std;

int main()
{
	string names[5];
	double grades[5];
	int i = 0;
	do
	{
		cout << "Please, enter a name of student " << i + 1 << " :";
		cin >> names[i];
		double sumgrd = 0;
		int j=0;
		cout << "Please, enter grades of student "<<i+1<<" (-1 - for stop) :";
		double grade;
		do
		{
			cin >> grade;//Read grades to -1
			if (grade == -1)break;
			sumgrd += grade;
			j++;
		} while (grade > 0);
		sumgrd /= j;
		grades[i] = sumgrd;
		i++;
	} while (i < 5);
	for (int j = 0; j < 5; j++)
	{
		cout << "\nStudent`s name: \t" << names[j]
			<< "\nStdent`s average grade:\t" << grades[j];
	}
	
}

LATEST TUTORIALS
APPROVED BY CLIENTS