I am supposed to use an array and a for loop to show the average of these grades. I am not sure the formula for average here and don't know if that is what has me messed up or not. It runs, lets me put in 1 grade and then freezes.

Windows XP (OS)
Microsoft Visual 2003

Error messages: C3861 and C2065 (dealing with line 42)

#include <cctype>
#include <iostream>
#include "stdafx.h"
using std::cout;
using std::cin;
using std::endl;
int _tmain(int argc, _TCHAR* argv[])
{int final[10];
int values[]={67,85,90,89,75,99,92,81,70,62};
int count = 0;
char reply =0;
 
cout<<endl;
cout<< "The students grades are: 67,85,90,89,75,99,92,81,70, and 62 \n";
cout<<sizeof values/sizeof values[0];
cout<<" The average of these grades is ";
cout<<endl;
int average=0;
cin>>final[count++];
cout<< " Are there any other grades (y/n)? ";
cin>>reply;
while(count<10 && (reply)=='y');
if (count==10)
cout<<endl << "Maximum number of grades has been reached."<<endl;
for(int i=0; i< count ; i++)
cout<<endl<<"The average of the grades is " <<std::setw(10)<<std::setprecision(2)<<std::fixed<<(static_cast<double>(total)/count)<<endl;
return 0;
}

I am sorry to sound so illiterate, but the instructor in my class does not give any support, or feedback. We were given a book and thrown in head first. I am new (very green) to this and I am completely lost!

Thanks for any help!
T

Recommended Answers

All 3 Replies

> I am not sure the formula for average here
Elementary maths perhaps?
You add up all the elements in your array - use a for loop
You divide the total by how many elements there are

Where is the loop that allows cin>>final[count++]; to accept more than one value?

Because of the ; on the line

while(count<10 && (reply)=='y');

you have here an endless loop. count and reply are never allowed to change.

It would also help if you start indenting you code properly so you can see what's going on. After each { indent 3-4 spaces, before each } unindent.

Thank you soooooooooo much for explaining that. That makes a lot of sense. I will go back and make the changes necessary.
Thanks again for the guidance.
T

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.