not printing out a few statements for the output

closed account (STCXSL3A)
i want the output be like:

5 total

3 invalid

2 valid

at the end

but it doesnt print the invalid or valid and total prints out after every run instead of at the end

1
2
3
4
5
6
7

void classify(int x, int y, int z)
{
   cout << "success";
    return ;
}
Last edited on
Do you want your output to be at the end of each iteration, or when your loop stops?
Last edited on
This was the exact post as http://www.cplusplus.com/forum/beginner/147280/ before you edited it.
closed account (STCXSL3A)
i want the output when the loop stops. sorry wasnt that clear earlier.

yeah that was my thread from yesterday but fixed lots of mistakes.
Well on line 19 you are calling the function that does the output. If you want it after the loop maybe do recursion or use a dynamic container such as a vector.
Try this:

EDIT:

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
#include <iostream>

using namespace std;

void classify (int,int,int);
bool validset(int,int,int);
bool validOrNot(void);

int main()
{
    int valid = 0;
    int invalid = 0;
    int x,y,z;
    char answer;
    int total = 0;
    bool validsetResult; 

    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;
         total++;
         
         if(validOrNot() == false)
         {
             cout << "The group is invalid" << endl;
             invalid++;
         }
         else if(validOrNot() == true)
         {
             cout << "The group is valid" << endl;
             valid++;
         }
         
         if (validset(x, y, z) == true)
         classify (x,y,z);
         else;
         cout <<    "Type c to continue; s to stop";
         cin >> answer;
         } while (answer == 'c');
         
         
         
         cout << total << " total" << endl;
         cout << valid << " valid" << endl;
         cout << invalid << " invalid" << endl;
         
 
         return 0;
}

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

    int vali = 0;
    int invali = 0;

    if (x < 0 || x > 300)
{
        cout << "The group is invalid" << endl;
        invali++;
        return(false);
}
    else if (y < 0 || y > 300)
{
        cout << "The group is invalid" << endl;
        invali++;
        return(false);
}
    else if (z < 0 || z > 300)
{
        cout << "The group is invalid" << endl;
        invali++;
        return(false);
}
    else
{
        vali++;
        return(true);

        cout << vali;
        cout << invali;
}
return(false);
}

void classify(int x, int y, int z)
{
   cout << "success" << endl;
    return ;
}

bool validOrNot(void)
{
    int x, y, z;
    if(validset(x, y, z))
    {
        return true;
    }
    
    else if(validset(x, y, z) == true)
    {
        return false;
    }
}   
Last edited on
That still outputs while it is iterating and not after it finishes iterating.
It outputs after the loop ends just as he asked for:


i want the output be like:

5 total

3 invalid

2 valid

at the end
closed account (STCXSL3A)
thanks srscode i tweaked ur code a bit and it worked perfectly thank you so much
Okay so he still wants it to print the "group is invalid" I was under the assumption he didn't want it to print anything until it was over. You may be right.
I did edit my first solution to a better version in case you didn't notice. :)
Last edited on
By the way
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    if (x < 0 || x > 300)
{
        cout << "The group is invalid" << endl;
        invali++;
        return(false);
}
    else if (y < 0 || y > 300)
{
        cout << "The group is invalid" << endl;
        invali++;
        return(false);
}
    else if (z < 0 || z > 300)
{
        cout << "The group is invalid" << endl;
        invali++;
        return(false);
}
can be one if such as

1
2
3
4
5
6
7
8
9
10
11
if(x < 0 || y < 0 || z < 0 || x > 300 || y > 300|| z > 300)
{
    cout << "The group is invalid" << endl;
    ++invalid;
    return false;
}
else
{
    ++valid;
    return true;
}
Topic archived. No new replies allowed.