You are here:



I've written a program for averaging lists of exam grades before but throwing in a percentage is throwing me for a loop. I don't know how to handle this information. Any help will be greatly appreciated.

//Write a program that asks the user to enter a student's midterm
//and final exam scores. The program should display the midterm and
//final exam scores and the student's final grade. Compute the final
//grade by taking the sum of 40% of the midterm exam score and 60% of
//the final exam score.

#include <iostream.h>

//using namespace std;

int main()
int. midterm,midterm;
double 40% mid;
60% final;

cout<< set precision()

//obtain input data
cout<<"\nEnter midterm";
cin>>midterm exam;
cout<<"\nEnter final";
cin>>;final exam;

//Do the calculations
final grade = double (midterm + final);

return 0;

Hello Joanne, thanks for the question.

I don't know if you formatted the code like that to make it more readable, but a lot of your syntax is off. For one thing, a variable name cannot start with a number in C++. Perhaps you were overthinking this problem some, because it's really not that difficult. The following code should help point you in the right direction:

using namespace std;

int main()
float midterm, final, average;

cout << "Enter a midterm grade:";
cin >> midterm;

cout << "Enter a final grade:";
cin >> final;

average = (.4f * midterm) + (.6f * final);

cout << "The average is: " << average << '\n';

return 0;

As you can see, it sums up the average correctly by adding 40 percent of the midterm with 60 percent of the final, as per the commented directions.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 All rights reserved.