C++ Program miscalculation -


#include <iostream>  using namespace std;  // variables static float fassignment, sassignment, tassignment, foassignment, midassignment, finalassignment, secassignment, total;  // function collect results float collector() {     printf("enter score first assignment: ");         cin >> fassignment;     printf("enter score second assignment: ");         cin >> sassignment;      printf("enter score third assignment: ");         cin >> tassignment;     printf("enter score fourth assignment: ");         cin >> foassignment;     printf("enter score midterm: ");         cin >> midassignment;     printf("enter score final: ");         cin >> finalassignment;     printf("enter score section grade: ");         cin >> secassignment;     return fassignment, sassignment, tassignment, foassignment, midassignment, finalassignment, secassignment; }  // function calculate final grade/score float calculator() {     static float average = ((fassignment + sassignment + tassignment + foassignment) / 4) * 0.4f;     midassignment * 0.15f;     finalassignment * 0.35f;     secassignment * 0.1f;     total = (average + midassignment + finalassignment + secassignment);     return total; }   int main()  {     collector();     calculator();     printf("your score is: ");     cout << total << endl;     return 0; } 

these instructions along correct result @ bottom

write program compute final grade programming course taking. here grading scheme:

final grades based on following: 40% assignments   15% midterm examination 35% final examination 10% class participation grade  

your program should ask user 4 assignment scores, midterm, final , section grades. then, final score calculated , printed. calculations, average 4 assignment scores , multiply 0.4 (40%). multiply midterm score 0.15, final 0.35 , participation grade 0.1. add results of these multiplications together.

use functions wherever can in program. can create function input passing in parameter string displayed in explanatory cout. here example run:

enter score first assignment. 75 enter score second assignment. 85 enter score third assignment. 82 enter score fourth assignment. 94 enter score midterm. 81 enter score final. 89 enter score section grade. 100 final grade is: 86.9 

but instead result when compile , run:

enter score first assignment: 75 enter score second assignment: 85 enter score third assignment: 82 enter score fourth assignment: 94 enter score midterm: 81 enter score final: 89 enter score section grade: 100 score is: 303.6 

i'm using visual studio 2013 community.

these lines not correct

midassignment * 0.15f; finalassignment * 0.35f; secassignment * 0.1f; 

you need use *= modify these variables

midassignment *= 0.15f; finalassignment *= 0.35f; secassignment *= 0.1f; 

the first method calculates temporary float, throws away since isn't assigned anything. in fact, compiler throws whole line away.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -