Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Why is this program not calculating the grades? It only returns 0 for all grades

ID: 3537262 • Letter: W

Question

Why is this program not calculating the grades? It only returns 0 for all grades.   


#include <iostream>

#include <cstdlib>   

#include <stdio.h>

#include <cmath>

#include<fstream>


double Homework ( double homework); // fuction for homework weight

double Midterm ( double midterm); // function for midterm weight

double Final ( double final); // function for final test weight

//function to calculate final grade

double CalcGrade (double homework, double midterm, double final, double totalScore, char grade);

//function to print

int Print( double homework, double midterm, double final, double totalScore, char grade);


int main()

{

//local delcarations

double homework;

double midterm;

double final;

double totalScore;

char grade;

  

//informs the user what this program does

printf("This program will calculate the final grade after homework ");

printf("midterm, and final test grades are inputed in. ");

system("cls"); //clears screen

  

//function calls

Homework(homework);

Midterm(midterm);

Final(final);

CalcGrade ( homework, midterm, final,totalScore, grade);

Print(homework, midterm, final, totalScore, grade);



system("pause"); //holds screen for dev C++


return 0;

} //end of main


/////////////////////////////HOMEWORK////////////

double Homework (double homework)

{

system("cls");


//function delcarations

int x ;

int i ;

double sum;

double homeworkMaxPts ;

// homework ;


//prompts users for input, and how to terminate

printf("Enter the homework assignment grades: Enter < 999 > to stop. ");


do //loop to collect input for homework grades

{

scanf("%d", &x);

if ( x <900) //termination of loop

sum += x; // calculated total amount of points

}while ( x < 900);


//prompts user to input maxmum score for each assignment

printf("Enter the max points for each assignemnt: ");

printf("Enter < 999 > to stop ");


//loop to collect imput for maximun points possible for homework

do

{

scanf("%d", &i);

if ( i < 900) //loop termination

homeworkMaxPts += i; // calculates total amount of points

}while ( i < 900);


//calculates the total weight of homework

homework =(sum*50/homeworkMaxPts);



system("pause");

return homework; // returns weighted homeword


} //end of homework


// Function to determine weight of midterm tests

double Midterm ( double midterm)

{


system("cls"); // clear screen


//declarations

int a=0;

int i=1;

double sum;

int x =1;

double midMaxPts = 0;

int b=0;

//midterm =0;


// prompts user to input midterm grades

printf("Enter the midterm grades: ");


//loop to calculate total midterm points

while(i<=3)

{

scanf("%d", &a);

sum +=a;

i++;

}//end of while

//prompts user to imput maximun amount of points possible

printf(" Enter the max points for midterm grades: ");


//loop to calculate total possible points

while ( x <=3)

{

scanf("%d", &b);

midMaxPts += b;

x++;

}//end of while


system("cls"); //clear screen

midterm = (sum*20/midMaxPts); //calculate midterm weights





  

system("pause");

return midterm; //return midterm


} //end of midterm


//Final test function

double Final ( double final)

{


system("cls"); //clear screen

//declarations

int final1, final2;

int finalSum = 0;

int points1, points2;

double finalMaxpts = 0;

final = 0;

//prompts user to input the two final grades

printf("Enter the final grades: " );

scanf("%d %d", &final1, &final2);

//prompts user to input the maximum points for finals

printf("Enter the max points possible for each grade: ");

scanf("%d %d", &points1, &points2);


finalSum = final1 + final2; //calculates total points made


finalMaxpts = points1 + points2; //calculates total points possible


final = (finalSum*30/finalMaxpts); //calculates weight of final


system("cls");

system("pause");

return final; // returns final weight

} //end final function


// grade calculation function

double CalcGrade (double homework, double midterm, double final, double totalScore, char grade)

{

//calculate final overall grade

totalScore = homework + midterm + final;

  

//to calculate the letter grade

if (totalScore >= 90)

grade = 'A';

else if ( totalScore >= 80)

grade = 'B';

else if ( totalScore >= 70)

grade = 'C';

else if ( totalScore >= 60)

grade = 'D';

else

grade = 'F';

system("pause");

return grade; //return grade

}


// print function   

int Print( double homework, double midterm, double final, double totalScore, char grade)

{

// prints out all grades

printf(" Final exam score was %2.2f ", final);

printf("Midterm exam score was %2.2f ", midterm);

printf("Homework assignments score were %2.2f ", final);

printf("------------------------------------------ ");

printf("Total score is %2.2f ", totalScore);

printf("Grade for the class is %c ", grade);


system("pause");


return 0;

} //

Explanation / Answer

//CORRECTED PROGRAM

//You needed to use the returned values from previous functions in the later functions


#include <iostream>

#include <cstdlib>   

#include <stdio.h>

#include <cmath>

#include<fstream>


double Homework ( double homework); // fuction for homework weight

double Midterm ( double midterm); // function for midterm weight

double Final ( double final); // function for final test weight

//function to calculate final grade

char CalcGrade (double homework, double midterm, double final, double totalScore, char grade);

//function to print

int Print( double homework, double midterm, double final, double totalScore, char grade);


int main()

{

//local delcarations

double homework;

double midterm;

double final;

double totalScore;

char grade;

  

//informs the user what this program does

printf("This program will calculate the final grade after homework ");

printf("midterm, and final test grades are inputed in. ");

system("cls"); //clears screen

  

//function calls

//update values at each step

homework = Homework(homework);

midterm = Midterm(midterm);

final = Final(final);

grade = CalcGrade ( homework, midterm, final,totalScore, grade);

Print(homework, midterm, final, totalScore, grade);



system("pause"); //holds screen for dev C++


return 0;

} //end of main


/////////////////////////////HOMEWORK////////////

double Homework (double homework)

{

system("cls");


//function delcarations

int x ;

int i ;

double sum;

double homeworkMaxPts ;

// homework ;


//prompts users for input, and how to terminate

printf("Enter the homework assignment grades: Enter < 999 > to stop. ");


do //loop to collect input for homework grades

{

scanf("%d", &x);

if ( x <900) //termination of loop

sum += x; // calculated total amount of points

}while ( x < 900);


//prompts user to input maxmum score for each assignment

printf("Enter the max points for each assignemnt: ");

printf("Enter < 999 > to stop ");


//loop to collect imput for maximun points possible for homework

do

{

scanf("%d", &i);

if ( i < 900) //loop termination

homeworkMaxPts += i; // calculates total amount of points

}while ( i < 900);


//calculates the total weight of homework

homework =(sum*50/homeworkMaxPts);



system("pause");

return homework; // returns weighted homeword


} //end of homework


// Function to determine weight of midterm tests

double Midterm ( double midterm)

{


system("cls"); // clear screen


//declarations

int a=0;

int i=1;

double sum;

int x =1;

double midMaxPts = 0;

int b=0;

//midterm =0;


// prompts user to input midterm grades

printf("Enter the midterm grades: ");


//loop to calculate total midterm points

while(i<=3)

{

scanf("%d", &a);

sum +=a;

i++;

}//end of while

//prompts user to imput maximun amount of points possible

printf(" Enter the max points for midterm grades: ");


//loop to calculate total possible points

while ( x <=3)

{

scanf("%d", &b);

midMaxPts += b;

x++;

}//end of while


system("cls"); //clear screen

midterm = (sum*20/midMaxPts); //calculate midterm weights





  

system("pause");

return midterm; //return midterm


} //end of midterm


//Final test function

double Final ( double final)

{


system("cls"); //clear screen

//declarations

int final1, final2;

int finalSum = 0;

int points1, points2;

double finalMaxpts = 0;

final = 0;

//prompts user to input the two final grades

printf("Enter the final grades: " );

scanf("%d %d", &final1, &final2);

//prompts user to input the maximum points for finals

printf("Enter the max points possible for each grade: ");

scanf("%d %d", &points1, &points2);


finalSum = final1 + final2; //calculates total points made


finalMaxpts = points1 + points2; //calculates total points possible


final = (finalSum*30/finalMaxpts); //calculates weight of final


system("cls");

system("pause");

return final; // returns final weight

} //end final function


// grade calculation function

char CalcGrade (double homework, double midterm, double final, double totalScore, char grade)

{

//calculate final overall grade

totalScore = homework + midterm + final;

  

//to calculate the letter grade

if (totalScore >= 90)

grade = 'A';

else if ( totalScore >= 80)

grade = 'B';

else if ( totalScore >= 70)

grade = 'C';

else if ( totalScore >= 60)

grade = 'D';

else

grade = 'F';

system("pause");

return grade; //return grade

}


// print function   

int Print( double homework, double midterm, double final, double totalScore, char grade)

{

totalScore = homework + midterm + final;

// prints out all grades

printf(" Final exam score was %2.2f ", final);

printf("Midterm exam score was %2.2f ", midterm);

printf("Homework assignments score were %2.2f ", final);

printf("------------------------------------------ ");

printf("Total score is %2.2f ", totalScore);

printf("Grade for the class is %c ", grade);


system("pause");


return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote