In: Computer Science
Get all homework scores for one student, calculate and display the sum of the scores, and also display the word “fail” if the sum is lower than 150. Note: we do not know how many homework scores each student will enter.
Ask the user how many homework scores there are at the beginning. Then, ask for a homework score at a time, for as many times as indicated by the user.
C++
C++ Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
//n stores count of homework scores
int score;
//score stores current homework score
int tot_score=0;
//tot_score stores total score of the student(initialised to
0)
for(int i=0;i<n;i++)
{
cin>>score;
tot_score+=score;
}
//print total score
cout<<tot_score<<endl;
//print "fail" if total score is less than 150
if(tot_score<150)
cout<<"fail"<<endl;
}
Screenshots and Results: