Your Math class has five 100 point tests over the course of a semester (and nothing else that counts toward your grade). In addition to getting an average score of 70/100 you must pass at least three individual tests in order to pass the class .

For example, if your scores are 68, 98, 65, 69 and 95, then you will fail the class because you failed three tests, even though your average score is 79/100. Or you might get scores of 81, 72, 73, 54 and 55. In this case you only failed two individual tests but your average is 67/100 so you still won't pass. If you get scores of 71, 70, 69, 68, 72 you will pass since you only failed two tests and your average is exactly 70/100.

Write a program that reads five integer scores from the console and outputs one of two words "pass" or "fail" depending on whether the student passes or fails the class .

Use five separate variables to store the scores. (Remember: you aren 't allowed to use loops or arrays for this program.)

Here is my source code:

``````#include<iostream>
using namespace std;

int main()
{
int a1, a2, a3, a4, a5;
int average = (a1 + a2 + a3 + a4 + a5)/5;
int total1 = a1 + a2 + a3;
int total2 = a1 + a2 + a4;
int total3 = a1 + a2 + a5;
int total4 = a1 + a3 + a4;
int total5 = a1 + a3 + a5;
int total6 = a1 + a4 + a5;
int total7 = a2 + a3 + a4;
int total8 = a2 + a3 + a5;
int total9 = a2 + a4 + a5;
int total10 = a3 + a4 + a5;

cin >> a1 >> a2 >> a3 >> a4 >> a5;

if((total1 >= 210 || total2 >= 210 || total3 >= 210
|| total4 >= 210 || total5 >= 210 || total6 >= 210
|| total7 >= 210 || total8 >= 210 || total9 >= 210
|| total10 >= 210) && average >= 70)
{
cout << "pass" << endl;
}
else
{
cout << "fail" << endl;
}

return 0;
}
``````

Here is my input:
68 98 65 69 95

Here is my output:
pass

Here is the expected output I want to get:
fail

Are there any ideas on how I can get the expected output for this program?

You do the arithmetic before entering the data.

## All 3 Replies

You do the arithmetic before entering the data.

Move line 19 to be between lines 6 and 7.

``````/*
Here is my input:
68 98 65 69 95

Here is my output:
pass

Here is the expected output I want to get:
fail
*/
``````

Regardless your code... Huh??? Those scores should satisfy your condition. So the expected output should be "pass" (average->79, a1+a2+a3->231). Are you getting it backward???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.