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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#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==true)
cout<< "this group is valid" << endl; //this part gives me an invalid when i have all three integers above 100 or below 0 but i need it to be invalid in one number is above 100 or below 0.
else
cout<< "this group is invalid" << endl;
invalid++;
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;
bool ans;
if (x && y && z >= 0 && x && y && z <= 100)
ans=true;
else {
ans= false;
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; }
invalid++;
return ans;
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 && x&&y<z) //this part is giving me trouble
cout<< "two numbers are the same and one is larger"<<endl;
else
cout<< "two numbers are the same and one 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;
}
|