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 ;
}
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.