this is what i did, but its not what the question is asking for
#include <iostream>
using namespace std;
int main()
{
double Exam_score_1, Exam_score_2, Exam_score_3, average;
// Display the exam scores
cout << "Please enter Exam score 1:";
cin >> Exam_score_1;
cout << "Please enter exam score 2:";
cin >> Exam_score_2;
cout << "Please enter exam score 3:";
cin >> Exam_score_3;
// Calculate the average of the exam scores
{
(average = Exam_score_1 + Exam_score_2 + Exam_score_3 / 3);
cout << "Your total average is: " << average << endl;
}
system("PAUSE");
return 0;
}
because the instructor said it should have the option in order for it to be a proper loop program, when i add the cout option to display the other score he said thats invalid cause its defeating the loop purpose. So am new to the program and lost for the solution
this is what i came up with and told it was wrong and defend the purpose of the loop,
#include <iostream>
using namespace std;
int main()
{
int i;
double scores;
double sum = 0;
double average = 0;
// Display the output with for, if,else loop
cout << "Please enter exam score one : ";
for(i=1; i<=3; i++)
{
cin >> scores;
cout << "Please enter next exam score: ";
if(scores > 0 && scores <= 100)
sum = sum + scores;
else
{
cout << "ERROR exam score must be between 0 to 100: " <<endl;
cout << "Please enter next exam score: ";
cin >> scores;
cout << "Please enter next exam score: ";
(scores > 0 && scores <= 100);
sum = sum + scores;
}
}
// Calculate the average
average = sum / 3;
// Display the output
cout << "Average is: " << average << endl;
yeah i need the loop by where its asking for the scores but it must display for the user enter score one and then score two and then score three.
for or while anyone
#include <iostream>
usingnamespace std;
int main()
{
double score, sum = 0, avg;
for(int i = 1; i <= 3; i++)
{
cout<<"Enter the score "<<i<<":\t";
cin>>score;
if(score < 0 || score > 100)
{
i--;
cout<<"You entered an invalid score. Score Range is from 0 to 100. Please try again\n";
}
else
{
sum = sum + score;
}
}
avg = sum/3;
cout<<"The average of your scores is "<<avg<<endl;
return 0;
}