Hello all,
I did this program below, it is meant to get a student name then 5 of his/her grades sums them up in a void function and calculate the average but outputs the average from the main
the problem is that the loop goes on and prints the prompt but takes no input
how can I fix that ?
# include <iostream>
# include <string>
using namespace std;
void avg (int grade[]);
int main()
{
char name;
double average;
int grade[5];
cout << "Student name" <<endl;
cin.get(name);
cout <<endl;
avg (grade);
cout << "The average is " << average <<endl;
return 0;
}
void avg (int grade[])
{
double sum=0;
double average;
for (int i=0; i<5; i++)
{
cout << "Please enter grade" <<endl;
cin >> grade[i];
sum= sum+grade[i];
average = sum/5;
}
}