Minimal amount of points needed to get grade "x" (C++) (explained) -
i doing challenge in c++ online , stuck on part.
basically, challenge following.
"derp student of college. favorite lesson math. end of year coming , derp asks himself how many points needed on last exam grade "k".
the teacher has given 5 tests year, maximum points can earned on test 100.
if <=60 = grade : 1 if >=60 && <= 69 = grade : 2 if >=70 && <= 79 = grade : 3 if >=80 && <= 89 = grade : 4 if >=90 && <= 100 = grade: 5 in case 89.8 points, have grade 4, not grade 5. know results of first 4 tests - t1,t2,t3,t4. have find how many minimum points derp needs on last test wanted grade "k".
input: in input, firstly, input wanted grade derp "k" (2<= k <= 5) in second line, input results of first 4 tests. (0 <= t1,t2,t3,t4 <=100)
output: have output minimum amount of points derp needs on last test in order have wanted grade "k" in math. if derp has no chance of getting grade "k" if last test has maximum points, have output "impossible"."
examples:
input: 5 100 100 100 100
output: 50
input: 5 10 20 30 40
output: impossible
input: 2 100 100 100 100
output: 0
input: 4 83 74 79 73
output: 91
here's got far.
#include <iostream> using namespace std; int main() { int grade; cin >> grade; int t1,t2,t3,t4; cin >> t1 >> t2 >> t3 >> t4; if((t1+t2+t3+t4)/4<=59) { cout << "grade: 1\n"; } else if((t1+t2+t3+t4)/4>=60 && (t1+t2+t3+t4)/4<=69) { cout << "grade: 2\n"; } else if((t1+t2+t3+t4)/4>=70 && (t1+t2+t3+t4)/4<=79) { cout << "grade: 3\n"; } else if((t1+t2+t3+t4)/4>=80 && (t1+t2+t3+t4)/4<=89) { cout << "grade: 4\n"; } else if((t1+t2+t3+t4)/4>=90 && (t1+t2+t3+t4)/4<=100) { cout << "grade: 5\n"; } int t5; return 0; } i have done math, , came this.
(100+100+100+100+x)/5>=90
(400+x)/5>=90
80+x/5 >= 90
x/5 >= 10
x >= 50
this first example input/output above, in math way. not sure how code though. ideas welcome!
thank you.
the point have calculate result using required average point number. basically, if averages needed 5, 4, 3 , 2 90, 80, 70 , 60, respectively, sum of scores of 5 tests 450, 400, 350 , 300. if sum of scores derp needs minus score has far more 100 points, it's impossible better mark. actual implementation might like:
int main() { int mark; int t1, t2, t3, t4; std::cin >> mark >> t1 >> t2 >> t3 >> t4; int total = t1 + t2 + t3 + t4; int total_needed = 5 * (60 + (mark - 2) * 10); int diff = total_needed - total; if (diff > 100) { std::cout << "impossible" << std::endl; } else if (diff <= 0) { std::cout << "you have got enough points" << std::endl; } else { std::cout << diff << " points needed yet" << std::endl; } return 0; }
Comments
Post a Comment