how do i count up the total at the end? program is able to run

closed account (STCXSL3A)
so after the program finish running i would like it to print the number of valid group and invalid group

for example

5 total

3 valid

2 invalid group


everytime i do this the program only prints out the total group.

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
void classify (int,int,int);
bool validset(int,int,int);

int main()
{
    int x,y,z;
    char answer;
    int total = 0;
    int vali = 0;
    int invali = 0;

    do  {
         cout <<    "Type in the first score" << endl;
         cin >> x;
         cout <<    "Type in the second score" << endl;
         cin >> y;
         cout <<    "Type in the third score" << endl;
         cin >> z;
         if (validset(x, y, z) == true)
         classify (x,y,z);
         else;
         cout <<    "Type c to continue; s to stop";
         cin >> answer;
         total++;
         vali++;
         invali++;
         cout << total;
         cout << vali;
         } while (answer == 'c');
         return 0;
}

bool validset(int x, int y, int z)
{

    if (x < 0 || x > 300)
{
        cout << "The group is invalid" << endl;
        return(false);
}
    else if (y < 0 || y > 300)
{
        cout << "The group is invalid" << endl;
        return(false);
}
    else if (z < 0 || z > 300)
{
        cout << "The group is invalid" << endl;
        return(false);
}
    else
{
        cout << "The group is valid" << endl;
        return(true);
}
return(false);
}
void classify(int x, int y, int z)
{
    cout << "group ran successfully" << endl;
    return ;
}
Last edited on
where is your classify function?
closed account (STCXSL3A)
forgot sorry about that
how much the group were valid and invalid.
- It does print that as far as i can see?


Edit: I'm not quite sure what you want to do, but if it's at the end of the program i assume it's after your do-while loop, so just add it there.
Last edited on
Well, you still have a good amount of work to go but right now the total is equal to the number of times it is ran plus one, every time it runs. This is because in line 27, you have it printing the total, plus one. So every time you run the program (or continue), it prints the total times it was ran, plus one. Aka, the first time it runs, it will be one. Second time will be 3, third time will be 5. Remove the ++ in line 27 to print the correct amount.
closed account (STCXSL3A)
yes thank you i fixed the total part forgot about the ++

but how do this to show the output?

for example

5 total

3 valid

2 invalid group

in your validset() function, add int& valid, int& invalid. Initialize them to 0, obviously. Every time true is returned, valid++. Every time false is returned, invalid++. Make sure you create these two integers in your main function as well and pass them in the argument.
Last edited on
Topic archived. No new replies allowed.