A Final Grade Program

I'm having trouble. I'm not finished my program just yet, but when I run it..I my final grade is 0. I don't understand. I put all number above 0 for the input in the test run but still get 0 as the total.

#include <iostream>
#include <cmath>
#include<iomanip>
using namespace std;

struct FinalGrade
{
double hw1;
double hw2;
double hw3;
double hw4;
double hw5;
double hw6;
double quiz1;
double quiz2;
double quiz3;
double test1;
double test2;
double ec1;
double ec2;
double ec3;
double ec4;
double ec5;
double finalgrade;
};

int main() {
FinalGrade Sean;
int score = 0;

cout << "This program will calculate your final grade for the semester" << endl;

cout << "Enter your grade for Homework 1: " << endl;
cin >> Sean.hw1;

cout << "Enter your grade for Homework 2: " << endl;
cin >> Sean.hw2;

cout << "Enter your grade for Homework 3: " << endl;
cin >> Sean.hw3;

cout << "Enter your grade for Homework 4: " << endl;
cin >> Sean.hw4;

cout << "Enter your grade for Homework 5: " << endl;
cin >> Sean.hw5;

cout << "Enter your grade for Homework 6: " << endl;
cin >> Sean.hw6;

cout << "Enter your grade for Quiz 1: " << endl;
cin >> Sean.quiz1;

cout << "Enter your grade for Quiz 2: " << endl;
cin >> Sean.quiz2;

cout << "Enter your grade for Quiz 3: " << endl;
cin >> Sean.quiz3;

cout << "Enter your grade for Test 1: " << endl;
cin >> Sean.test1;

cout << "Enter your grade for Test 2: " << endl;
cin >> Sean.test2;

cout << "Enter your grade for Extra Credit Assigment 1: " << endl;
cin >> Sean.ec1;

cout << "Enter your grade for Extra Credit Assigment 2: " << endl;
cin >> Sean.ec2;

cout << "Enter your grade for Extra Credit Assigment 3: " << endl;
cin >> Sean.ec3;

cout << "Enter your grade for Extra Credit Assigment 4: " << endl;
cin >> Sean.ec4;

cout << "Enter your grade for Extra Credit Assigment 5: " << endl;
cin >> Sean.ec5;

score += Sean.hw1 + Sean.hw2 + Sean.hw3 + Sean.hw4 + Sean.hw5 + Sean.hw6 + Sean.quiz1 + Sean.quiz2 + Sean.quiz3 + Sean.test1 + Sean.test2 + Sean.ec1 + Sean.ec2 + Sean.ec3 + Sean.ec4 + Sean.ec5;

Sean.finalgrade = score/500 * 100;

cout << "Your score for the end of the semester is" << Sean.finalgrade << endl;

return 0;
}
replace
Sean.finalgrade = score/500 * 100;
with
Sean.finalgrade = score/500.0 * 100.0;

You're running into integer division which will remove any digits after the decimal.
thanks!
you have to add double (score/500 * 100) otherwise it output the result as an int
Topic archived. No new replies allowed.