c++ - My program for calculating the final grade doesn't calculate it and I can't tell why -
i've been trying write c++ program calculates end of year grade (an exercise given google education c++ course). program works, except fact it doesn't calculate final grade, instead, outputs "0". have searched code , can't seem find problem.
#include <iostream> using namespace std; int check(int a) { if (!(cin >> a)) { cout << "come on, isn't score" << endl; return 0; } } int assignments() { int assignment1 = 0; int assignment2 = 0; int assignment3 = 0; int assignment4 = 0; cout << "enter score first assignment. "; check(assignment1); cout << "enter score second assignment. "; check(assignment2); cout << "enter score third assignment. "; check(assignment3); cout << "enter score fourth assignment. "; check(assignment4); return ((assignment1 + assignment2 + assignment3 + assignment4) / 4 * 0.4); } int mid() { int midterm = 0; cout << "enter score midterm. "; check(midterm); return (midterm * 0.15); } int finalex() { int finals = 0; cout << "enter score final. "; check(finals); return (finals * 0.35); } int participation() { int parti = 0; cout << "enter class participation grade. "; check(parti); return (parti * 0.1); } int main() { int assign = assignments(); int midt = mid(); int fingra = finalex(); int partigra = participation(); cout << "the final grade is: " << assign + midt + fingra + partigra << endl; }
(the reason have different program every grade type because course states should make many functions possible)
either should pass value check() reference or make check return input value.
change
int check(int a)
to
int check(int& a)
second method
modify check
int check(int a) { if (!(cin >> a)) { cout << "come on, isn't score" << endl; return a; } }
and use return value assign input variables.
int midterm = 0; cout << "enter score midterm. "; midterm=check(midterm);
Comments
Post a Comment