ok so for this program i have to make a main program that calls four different functions. the introduction function doesn't return anything and it only prints what the program will do. the second function aretheyvalid receives three integers that represent three test scores. the third function is the one that i am having a problem with. its called aretheysame and it receives three integers and the function compares the three integers and prints one of these four messages: all three numbres are the same, two numbers are the same and the third is larger (this can happen in three ways like first is larger or second is larger), two numbers are the same and the third is smaller (also can happen in three ways), and all three numbers are different, the last function is roundscore which rounds the number. the "two are the same and one is smaller" part in the output comes after the rounded numbers and it is referring to the rounded numbers. for example, in the output above two numbers round to 80 and one number rounds to 70 so thats why it says two are the same and one is smaller. im not sure how i can print that in the aretheysame function. ok so here is what i done so far:
#include <iostream>
using namespace std;
void introduction ();
bool aretheyvalid (int x, int y, int z);
void aretheysame (int x, int y, int z);
int roundscore (int score);
int main()
{
int test1, test2, test3, groups=1, valid=0, invalid=0;
introduction();
while (groups <=20) {
cout<< "Group "<< groups << endl;
cout<< "original data: " << endl;
cin>> test1 >> test2 >> test3;
bool ans;
ans= aretheyvalid(test1, test2, test3);
if (ans)
cout<< "this group is valid" << endl; //i need this part to say invalid when only one number is above 100 or below 0.
else {
cout<< "this group is invalid" << endl; }
aretheysame(test1, test2, test3);
cout<< test1 << " is rounded to " << roundscore (test1) << endl;
cout<< test2 << " is rounded to " << roundscore (test2) << endl;
cout<< test3 << " is rounded to " << roundscore (test3) << endl << endl;
groups++;
}
cout<< "the total number of valid groups are " << valid << endl;
cout<< "the total number of invalid groups are "<< invalid << endl;
cout<< "the total number of groups are " << groups << endl;
return 0;
}
//this function will describe what the program does.
void introduction () {
cout << "This program will print out test scores in the main program. The aretheyvalid function will determine if these scores are valid. The aretheysame function will compare the scores to messages. The roundscore function will round the test scores. The program will print out all the results of the functions."<< endl << endl;
return ;
}
//aretheyvalid
bool aretheyvalid (int x, int y, int z) {
int invalid=0, valid=0;
bool ans;
if (x && y && z >= 0 && x && y && z <= 100) {
valid++;
ans=true;}
else {
if (x < 0)
cout<< x << " is too small" << endl;
if (y < 0)
cout<< y << " is too small" << endl;
if (z < 0)
cout<< z << " is to small" << endl;
if (x >100)
cout<< x << " is too big" << endl;
if (y > 100)
cout<< y << " is too big" << endl;
if (z > 100)
cout<< z << " is too big" << endl;
ans=false; }
invalid++;
return ans;
return valid;
return invalid;
}
//aretheysame
void aretheysame (int x, int y, int z) {
if (x == y && y == z)
cout<< "all three numbers are the same" << endl;
else {
cout<< "all three numbers are different" << endl;
if (x==y && y<z)
cout<< "two numbers are the same and third is larger" << endl;
else
cout<< "two numbers are the same and third is smaller" << endl;
if (y==z && z<x)
cout<< "two numbers are the same and the first is larger" << endl;
else
cout<< "two numbers are the same and the first is smaller" << endl;
if (x==z && x<y)
cout<< "two numbers are the same and the second is larger" << endl;
else
cout<< "two numbers are the same and the second is smaller" << endl;
}
return ;
}
//roundscore will round the each test score to the nearest 10 and it will return the rounded score to the main program which will print them out.
int roundscore (int score) {
int r;
r = score%10;
if (r >= 5)
score = score + (10-r);
else
score = score - r;
return score;
}
here is what the output should look like if it is valid:
original data: 72 83 78
this is a valid group
all three numbers are different
72 is rounded to 70
83 is rounded to 80
78 is rounded to 80
two are the same and one is smaller <<im not getting this part
here is what the output should look like if it is invalid:
original data: -72 78 781
-72 is too small
781 is too big
this is a invalid group
thanks :)