Wrong output in function

Hello, this function(ratethegroup) is giving me the wrong outputs when entering numbers. The function receives 4 numbers, total of 3 scores and the 3 scores. The first if should only output if the 3 scores are greater than or equal to 700. The second should only output if 2 out of the 3 scores are 700 or above. The last should only output when one of the score is 700 or above. The total should always be 2100 or above. When entering 3 scores of 650,650,800 it outputs "outstanding" when it should output "Lop-sided".


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
#include <iostream>
using namespace std;
int isitavalidgroup(int x,int y,int z);
int classify(int x,int y,int z);
void rateonescore(int x);
int findtotalscore(int x,int y,int z);
void ratethegroup(int x, int y, int z, int a);

int main()
{
	int x, y, z,a;
	cout << "What are your SAT scores?" << endl;
	cin >> x >> y >> z;
	cout << x <<" "<< y <<" "<< z << endl;

	a=isitavalidgroup(x,y,z);

	if (a == true) {
		cout << "valid" << endl;
		classify(x,y,z);
	
	}
	else
		cout << "Invalid" << endl;
}

int isitavalidgroup(int x,int y,int z)
{
		
		if ((x <= 800) && (x >= 200)) 
			x = true;
		else 
			x = false;
		if ((y <= 800) && (y >= 200)) 
			y = true;
		else 
			y = false;
		if ((z <= 800) && (z >= 200)) 
			z = true;
		else 
			z = false;
			
		
		cout << endl;


		if ((x) && (y) && (z) == true)
			return true;
		else
			return false;
}
int classify(int x,int y,int z)
{
	int a;
	rateonescore(x);
	rateonescore(y);
	rateonescore(z);

	a=findtotalscore(x,y,z);
	cout << a << endl;

	ratethegroup(x,y,z,a);
	return 0;
}
void rateonescore(int x)
{
	if (x<500)
		cout << "Less than 500" << endl;
	if ((x >= 500) && (x<800))
		cout << "500 or above" << endl;
	if (x == 800)
		cout << "Perfect score" << endl;
	
}
int findtotalscore(int x,int y,int z)
{
	return x + y + z;
}
void ratethegroup(int x, int y, int z, int a)
{
	if ( (a >= 2100) && ( (x) && (y) && (z) >= 700) ) {
		cout << "outstanding" << endl;
	}
	if ((a >= 2100) && ((x) && (y) >= 700)&& (z<700)) {
		cout << "Very good" << endl;
	}
	if ((a >= 2100) && ((x >= 700))&&(y<700)&&(z<700)) {
		cout << "Lop-sided" << endl;
	}
}
Last edited on
This is not correct:
1
2
3
(x) && (y) && (z) > 700
//write instead
x > 700 && y > 700 && z > 700

Your notation isn't possible because integers will always evaluate to true if they aren't zero.

Also, try naming your funtions with camelCase, e.g:
rateTheGroup()
findTotalscore()
This improves readability.

Last edited on
also take a look here, seems similar/same problem: http://www.cplusplus.com/forum/beginner/212281/
Topic archived. No new replies allowed.