Im doing a program that asks to enter a student's grades on four exams, I have to display the four grades and the average of the four grades, to the nearest tenth. The most problem im having is using the variable call total_grade which i have to initialize to zero.

#include < iostream>
#include <iomanip>

using namespace std;

int main()
{
  int    exam 1,                  // Exam 1 grade
          exam 2,                // Exam 2 grade
          exam 3,              //  Exam 3  grade
          exam 4;             //  Exam 4 grade
 double averagr;          // Average of the four exam grades
  //  Setup output stream for one decimal place
 cout << setpresion(1)
       << setiosflags(ios::fixed)
       << setiosflags(ios::showpoint);
 
 cout << "Enter the grade for Exam 1: ";
 cin >>  100
 cout << "Enter the grade for Exam 2: ";
 cin >> 84
cout << "Enter the grade fot Exam 3: ";
cin >> 78
cout << "Enter the grade for Exam 4: ";
cin >> 94

// This program asks the user to enter a student
// grades on four exams and display the for grades
// and the average of four exams rounded to the
// nearest tenth.

total_grade=double (exam1 + exam2+ exam3 + exam4)/4;
cout << endl;
cout << "The average of the four exams is " << average << endl;
return 0;
}

cout << "Enter the grade for Exam 1: ";
cin >> 100
//...

I assume what you want is to have those as the inputs, right? That doesn't work. You can't read in a number like that. What you're going to have to do is read in a variable and when you run the program the variable is assigned the number you type in (see below).

>> int exam 1
You can't do that either. Variables cannot have spaces in their name. int exam_1 is more what you want. Or you can do what you did later on in your code and call them exam1, exam2 etc.

int grade_1;
cout<< "Enter grade for exam: ";
cin> >grade_1;

cout<< "You entered: " << grade_1;

The rest looks OK.

thank you so much im taking a online class for C++ and some of the material i wasnt familar with

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.