need help with my program please!!!

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), 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. ok so here is what i done so far:
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;
}


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 :)
if (x==y && x&&y<z) //this part is giving me trouble ¿what kind of trouble?
By the way, if you want to test that both 'x' and 'y' are smaller than 'z' you should write if( x<z and y<z )
&& does not group variables to do a (`any', `all', `none') test

> two numbers are the same and the third is larger (this can happen in three ways)
Either test all the ways, or sort the numbers to simplify.

Also if(ans==true)
`ans' is already a bool, if you compare it against true (another bool) you would get a bool.
Simply do if(ans)

PS: please note that your post is too wide, making the introductory text unreadable.
Try to limit how much do you put in one line.
Last edited on
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.

oh and sorry about the post being too wide.
Topic archived. No new replies allowed.