-2
#include <iostream.h>

void main()
{
double average;
int GradestoAvg;
int sum = 0;

{
cout << "This program averages grades that the user provides. " << endl;
cout << "How many grades do you want to average?" << endl;
cin >> GradestoAvg;

cout << "Enter Grades:" << endl;
cin << sum;
}


while (GradestoAvg > 0)
average = sum / GradestoAvg;
cout << "The average of the grades is << average <<" endl;

Why am I getting a compiler error near the top? It tells me it is expecting a ; near the top where my double average and int GradestoAvg are located. Any thoughts?

kguest
  • 3,804
  • 3
  • 29
  • 31
user3416645
  • 23
  • 1
  • 8
  • You are missing a closing `}` for the `main()` function. – rpsml Apr 28 '15 at 13:56
  • 7
    The main problem is that you're writing a dialect of C++ that's been obsolete for nearly twenty years. I suggest throwing away whichever book you're learning from and getting a [modern one](http://stackoverflow.com/questions/388242). – Mike Seymour Apr 28 '15 at 13:57
  • 1
    for future occasions, try putting out the error, you are having – Angel Angel Apr 28 '15 at 14:09

3 Answers3

0

The correct include is <iostream> and you need to qualify cout and other std-scoped variables with std:: (std::cout, std::endl).

Also note the potential infinite loop (the while), as the condition doesn't appear to change.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
0

other than as mentioned in other answer, check this line :

cin << sum;

is cin >> sum;

Angel Angel
  • 19,670
  • 29
  • 79
  • 105
0

first thing, you have some mistakes with the cin couts there... i think something like this would be better

#include <iostream>
using namespace std;

int main()
{
  double average;
  int GradestoAvg;
  int sum = 0;
  int tmp;
  cout << "This program averages grades that the user provides. " << endl;
  cout << "How many grades do you want to average?" << endl;
  cin >> GradestoAvg;
  while (GradestoAvg > 0)
  {
    cout << "Enter Grades:" << endl;
    cin >> tmp;
    sum+= tmp;
    GradestoAvg--;
  }

  average = sum / GradestoAvg;
  cout << "The average of the grades is" << average << endl;
  return 0;
}
Bill
  • 14,257
  • 4
  • 43
  • 55
David Rubin
  • 123
  • 7
  • what are you talking about? – David Rubin Apr 28 '15 at 14:13
  • 1
    not angry, it was just that if he was doing some work or practice, you are the finished – Angel Angel Apr 28 '15 at 14:20
  • Thanks for your help David. I was just having trouble with the compiling of this program seeing as how this is an assignment I just needed to see what was going on there. The C++ compiler we are using might not allow for certain things but I'll check it out. – user3416645 Apr 28 '15 at 14:30
  • no problem David, @user3416645 if the this answer helped fix his mistake, or fix the error Consider upvote or acept, thank you, could also read this: -> http://stackoverflow.com/tour – Angel Angel Apr 28 '15 at 14:37