use a proper iterative structure to write a programin c++ that will read names and exam scores of students saving them in two different arrays. the class average is to be calculated and printed at the end of the report score can range from 0 to 100. the last record contains a blank name and a score 999 and is not be included in the calculations
#include<iostream>
using namespace std;
struct stud{
int score;
char name[50];
};
int main(){
int n;
cout<<"Enter the number of the student"<<endl;
cin>>n;
struct stud names[n];
struct stud scores[n];
double sum = 0.0;
for(int i=0; i<n; i++){
cout<<"Enter the student name"<<endl;
cin>>names[i].name;
cout<<"Enter the score for "<<names[i].name <<endl;
cin>>names[i].score;
sum += names[i].score;
}
cout<<"The class average is\t"<<sum/n<<endl;
}
Comments
Leave a comment