C++ Function Assignment grade calculator -
my programming lecturer teaching how write functions, terribly might add, make program calculates grade of students work. here specs on it.
- score 1 weighted 0.3,
- score 2 weighted 0.5, and
- score 3 weighted 0.2. if sum of scores greater or equal 85 grade 'a'. if sum of scores greater or equal 75 grade 'b'. if sum of scores greater or equal 65 grade 'c'. if sum of scores greater or equal 50 grade 'p'. otherwise grade 'f'.
so wrote code follows:
#include <iostream> using namespace std; void calculategrade() { int score1, score2, score3; int percentdec; cin >>score1>>score2>>score3; percentdec = (score1+score2+score3); if (percentdec >= 85) { cout << "the course grade is: a"; } else if (percentdec >= 75) { cout << "the course grade is: b"; } else if (percentdec >= 65) { cout <<"the course grade is: c"; } else if (percentdec >= 50) { cout <<"the course grade is: p"; } else { cout <<"the course grade is: f"; } } //end of calculategrade() int main() { calculategrade(); return 0; }
which works fine on ide when put program determines whether our answer correct doesn't work, because ordinarily asked put stuff in main()
because function , it's not in main()
doesn't work that. given example , i'm throw how dumb is. don't know how program work way want it.
cout << "the course grade is: " << calculategrade(90, 50, 99) << endl;
cheers help.
this not forum getting answers homework questions, although job on showing have tried. here areas at:
1) instructor showing you can decompose code functions. he/she wants wrtie function calculategrade work cout << "the course grade is: " << calculategrade(90, 50, 99) << endl;
. every function declaration in c++ has 3 parts it:
return_type functionname(param1_type param1, param2_type param2,...) { // implementation }
the functionname function referred (calculategrade in case), parameters information need pass function thing, , return type function give back. in case, instructor saying calculategrade take 3 integers parameters , must return string representing grade of student's scores. function should like:
string calculategrade(int score1, int score2, int score3) { // ... }
2) comments rightly pointed out, aren't multiplying score1, score2, , score3 respective weights in calculategrade() method.
from question , comments, feeling grasp of functions not solid. rather complaining teacher (be his/her fault or not), suggest read here it. there plethora of online resources learn basics of c++ programming.
Comments
Post a Comment