Help need asap plz

Have to writing a c++ program, using loop to calculate the average of 3 score
And display, each exam score should be from 0 to 100.
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;
}
how to applying loops to that program?,
I think this is exactly what you are asking for...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>

using namespace std;

int main()
{
	double scores;
	double sum=0;
	double avg=0;

	cout << "Enter three scores: ";
	for(int i=1; i<=3; i++)
		{
			cin >> scores;

			if(scores>0 && scores<=100)	
				sum=sum+scores;

			else
			{ cout << "Invalid Input." << endl;
			system ("pause");  }
		}

	avg=sum/3;

	cout << "Average is: " << avg << endl;

	system ("pause");


} 
ok thanks it super close to it, some the codes you use its new to me. but
I believe am able to get it now, thanks again
ok i notice the error your talking about, trying to correct it at the moment, sorry about the late reply
could you plz help. How could you loop the program so that it prompt the user by display for the different
score 3
score 2
score 1

#include <iostream>
using namespace std;

int main()
{
double scores;
double sum=0;
double avg=0;

cout << "Enter three scores: ";
for(int i=1; i<=3; i++)
{
cin >> scores;

if(scores>0 && scores<=100)
sum=sum+scores;

else
{ cout << "Invalid Input." << endl;
system ("pause"); }
}

avg=sum/3;

cout << "Average is: " << avg << endl;

system ("pause")

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
the loop should have a display with enter score two and then score one before it find the average
could you plz help me
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;

system ("pause");
return 0;
}
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
btw sry abt the late reply got loads of assignment.
A simple would be

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>

using namespace 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;
}
your code had score > 0

needs to be

if (score < 0 || score > 100)

but you could nest a loop and use

while (score < 0 || score > 100)
{
cout << "ERROR: score must be from 0 -100\n\nEnter again: ";
cin >> score;
}

this will allow the user to re-enter a score
thanks for the help, it woks great
Topic archived. No new replies allowed.