What is wrong with my function?

3 integers named score1,score2 and score3. and I assign their numbers ( has to be between 0 and 300) has to keep printing scores until sentinel is reached ( -999 ) also has to count the amount of valid groups and invalid.Theres a few other things I need to implement into the program but I feel if I understand this I might be able to do the rest. Any help would be appreciated. Can't wrap my head around this function idea. Have been trying for days now.

The function does not need to be the way I wrote it. The professor gave me a tip and said to use 6 "if" statements.

#include <iostream>
#include <fstream>
using namespace std;


int validGroup(int a,int b,int c,ofstream &); //ofstream for the outfile later
int main()

{

int score1,score2,score3;
int numvalidgroups = 0;
//int numinvalidgroups;
int numgroups = 0;


cout << "Enter number: ";
cin >> score1 >> score2 >> score3;

while (score1 != -999 && score2 != -999 && score3 != -999)

{
//validGroup;
cout << endl << score1 << " " << score2 << " " << score3 << endl;
validGroup;
numgroups++;
cout << endl << "Enter number: ";
cin >> score1 >> score2 >> score3;
}
cout << endl << "There are " << numgroups << " group(s). " << "There are " << numvalidgroups << " valid group(s).";

return 0;
}

int validGroup(int a,int b,int c,int &d)

{
d = 0;
//int numinvalidgroups = 0;
cout << "working";

if (a >= 0 && a <= 300)
{
if (b >= 0 && b <= 300)
{
if (c >= 0 && c <= 300)


d++;

return d;
}
}

}



Last edited on
I fail to understand something, perhaps it's quite basic :
3 integers ... ( has to be between 0 and 300)
... in which case how do we even reach the sentinel value of -999?
The program needs the numbers to be from 0-300 and if it goes below or above has to print invalid and continue on to the next set. My professor told us that we could use -999 as a sentinel since he hasn't taught us how to stop the process another way. The only way I can reach that is if I input it myself to stop the program.
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
#include <iostream>
#include <fstream>
using namespace std;


int validGroup(int a,int b,int c,ofstream &); //ofstream for the outfile later
int main()

{

int score1,score2,score3;
int numvalidgroups = 0;
//int numinvalidgroups;
int numgroups = 0;


cout << "Enter number: ";
cin >> score1 >> score2 >> score3;

while (score1 != -999 && score2 != -999 && score3 != -999)

{
//validGroup;
cout << endl << score1 << " " << score2 << " " << score3 << endl;
validGroup;
numgroups++;
cout << endl << "Enter number: ";
cin >> score1 >> score2 >> score3;
}
cout << endl << "There are " << numgroups << " group(s). " << "There are " << numvalidgroups << " valid group(s).";

return 0;
}

int validGroup(int a,int b,int c,int &d)

{
d = 0;
//int numinvalidgroups = 0;
cout << "working";

if (a >= 0 && a <= 300)
{
if (b >= 0 && b <= 300)
{
if (c >= 0 && c <= 300)


d++;

return d;
}
}

}
Topic archived. No new replies allowed.