This is part a of a 3 part assignment, and im not sure why it isn't returning the correct average.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273`` ``````#include #include using namespace std; bool GetStudent(char Name[]); int InputData(char Name[][15], double Grade[]); void OutputData(int N, char Name[][15], double Grade[]); int main() { int Count; char Name[10][15]; double Grade[10]; Count = InputData(Name, Grade); OutputData(Count, Name, Grade); cout << "\n\n"; return (0); } int InputData(char Name[][15], double Grade[]) { int i=0; while(GetStudent(Name[i])) { cout << "What is " << Name[i] << "'s grade? "; cin >> Grade[i++]; } return --i; } bool GetStudent(char Name[]) { char YN; cout << "\nDo you want to enter a new student? (Y/N) "; cin >> YN; if(YN > 90) YN -= 32; if(YN != 'Y') return false; else { cout << "\nWhat is the student's name? "; cin >> Name; return true; } } void OutputData(int N, char Name[][15], double Grade[]) { int i; double sum=0; cout << "\n"; for(i=0; i<=N; ++i) { sum += Grade[i]; } double avg = sum /N; cout << setw(16) <
What data are you inputting, and what results are you getting?

line 65 change to:
`double avg = sum /(N*1.0);`

edit:
or the proper way is to static_cast N to a double.
Last edited on
Topic archived. No new replies allowed.