Unable to print my cout

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#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);

int main()
{

            int numgroups=0;
            int validgroups=0;
            int invalidgroups=0;
            int score1, score2, score3;
            char answer;


introduction();

        do
{
        cout<<"Type in the student's three scores from 0 to 100"<<endl;
        cin>>score1;
        cin>>score2;
        cin>>score3;

if (aretheyvalid(score1, score2, score3)==true)
{
        validgroups++;
        cout << "the grades are valid" <<endl;
}

if(aretheyvalid(score1,score2,score3)==false)
{
        invalidgroups++;
        cout<<"the grades are invalid"<<endl;
}
        cout<<"Enter the next set of scores"<<endl<<endl;
        numgroups++;
        cout <<"Type in y to continue, n to stop"<<endl;
        cin >>answer;
        cout<<endl<<endl;
}
while(answer=='y');
            aretheysame(score1, score2, score3);
        cout<<"the original scores are: "<< score1 <<" "<< score2<<" " <<score3<<endl;
        cout<< score1 << " is rounded to " << roundscore (score1) << endl;
        cout<< score2 << " is rounded to " << roundscore (score2) << endl;
        cout<< score3 << " is rounded to " << roundscore (score3) << endl << endl;

        cout<<"We processed "<< numgroups <<" groups"<<endl;
        cout<<"We processed "<< validgroups <<" valid groups"<<endl;
        cout<<"We processed "<< invalidgroups<<" invalid groups"<<endl;

return 0;
}

void introduction()
{
        cout<<"This program will read in a student's 3 grades,"<<endl;
        cout<<"evaluate if they are valid, it will check if they"<<endl;
        cout<<"increase,decrease or stay the same,"<<endl;

return;
}

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;

}

void aretheysame(int x, int y, int z)
//this is the part where I can't get any of the couts to my print screen.
{
    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)                             
        cout<< "two numbers are the same and one is larger"<<endl;
    else
        cout<< "two numbers are the same and one is smaller"<<endl;

        return ;
}


int roundscore (int score)
{
        int r;

        r = score%10;

        if (r >= 5)
            score = score + (10-r);
        else
            score = score - r;

        return score;
}

Can you tell more :

1- What's wrong? Output, Result,....
2- Description?
3- Your expected example output
4- Where your doubt is... (important)

Hope this helps.
Last edited on
Remember that the do while loop states that if you type 'y' to continue, it will start the loop again, not actually continue through the program. Pressing the 'n' should exit the loop and print what you wrote in your function.

Your program will end straight away though since nothing is stopping it from closing, which means you won't even have enough time to see what prints.
Try add the line

system("pause");
before
return 0;

so that you can actually see what happens before it closes.

Also, you should check your logic from the function 'aretheysame'. At first glance it looks like it will say "All values are different" even if two are the same. Have a play around with your if statements to see if you can get it working correctly
Yeah I fixed the statements for the aretheysame and it works. Thanks!
Topic archived. No new replies allowed.