In: Computer Science
please i want solution for this question with algorithm and step by step with c++ language
#include <iostream>
using namespace std;
int main() {
int n, score = 0,score_var, total_var, total = 0;
cout << "How many exercises to input? ";
cin>>n;
for(int i = 1; i<=n ; ++i){
cout<<"Score received for exercise "<<i<<": ";
cin>>score_var;
cout<<"Total points possible for exercise "<<i<<": ";
cin>>total_var;
score = score + score_var;
total = total + total_var;
cout<<endl<<endl;
}
cout<<"Your total is "<<score<<" out of "<<total<<", or "<<score*100.0/total<<" %"<<endl;
}
============================================================
SEE OUTPUT
Algorithm Score( )
START
1. Read number of exercises , Read(n)
2. For loop from i = 1 to n
read score for execise i
read total for execise i
Keep summing total ans score read from user
3. Once Loop ends, print the score, total and percentage
END
Thanks, PLEASE COMMENT if there is any concern. PLEASE UPVOTE
WHILE LOOP
#include <iostream>
using namespace std;
int main() {
int n, score = 0,score_var, total_var, total = 0, i = 1;
cout << "How many exercises to input? ";
cin>>n;
while(i<=n){
cout<<"Score received for exercise "<<i<<": ";
cin>>score_var;
cout<<"Total points possible for exercise "<<i<<": ";
cin>>total_var;
score = score + score_var;
total = total + total_var;
cout<<endl<<endl;
++i;
}
cout<<"Your total is "<<score<<" out of "<<total<<", or "<<score*100.0/total<<" %"<<endl;
}