void function problem

closed account (STCXSL3A)


i have problem with void findpattern function. the void function always return the same couts.
[code]
void findpattern (int,int,int);
void classify (int,int,int);
void validset(int,int,int);

int main()
{
int x,y,z;
char answer;

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;
validset (x,y,z);
classify (x,y,z);
cout << "Type c to continue; s to stop";
cin >> answer;
} while (answer == 'c');
return 0;
}

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

if (x < 0 || x > 300)
cout << "The group is invalid";
else if (y < 0 || y > 300)
cout << "The group is invalid";
else if (z < 0 || z > 300)
cout << "The group is invalid";
else
cout << "The group is valid";
return ;
}

void classify(int x, int y, int z)
{
findpattern (x,y,z);
return ;
}

void findpattern (int x, int y, int z)
{
if (x==y==z)
cout << "all scores were the same";
if (x>y>z)
cout << "the scores are going steadily upward";
if (x<y<z)
cout << "the scores are going steadily downward";
if (x>y<z)
cout << "the scores first went up, then went down";
if (x<y>z)
cout << "the scores first went down, then went up";
if (x==y)
cout << "two consecutive scores were the same, and the other was either higher or lower";
if (x==z)
cout << "two consecutive scores were the same, and the other was either higher or lower";
if (y==z)
cout << "two consecutive scores were the same, and the other was either higher or lower";
return ;
}
What exactly is the problem? And please use code tags/brackets.
Last edited on
Entering the samber number the first 2 times, result in both of the following statements being executed.

1
2
3
4
if (x<y<z)
cout << "the scores are going steadily downward";
if (x>y<z)
cout << "the scores first went up, then went down";


I assume first the compiler check if x < y in case it's true, next it checks if 1 is less than z (since true is equal to 1) and unless z is 0 the condition becomes true.
Last edited on
closed account (STCXSL3A)
sorry about the tag but yes that is the problem how do i fix it? i tried something earlier but it didnt work
I'm gonna help you with one of the statements, this is one of the ways it can be done:

1
2
if (x == z && z == y && y == x)
cout << "all scores were the same";


&&
What this is doing is that if x is equal to z AND x is equal to y, the condition becomes true.

||
Instead of AND it means OR.

- Updated the code above, as it looks now is what i meant to write.
Last edited on
Topic archived. No new replies allowed.