hi ive developed a code to sort 3 numbers and pick out the middle one. the numbers are distinct.
#include<iostream>
using namespace std;
int main( ) {
int X, Y, Z;
cout<<"please 1st number ";
cin>>X;
cout<<"please 2nd number ";
cin>>Y;
cout<<"please 3rd number ";
cin>>Z;
if (Z>X>Y) (Y>X>Z)
cout<<"this is the middle number "<<X<<endl;
else if (X>Y>Z) (Z>Y>X)
cout<<"this is the middle number "<<Y<<endl;
else if (X>Z>Y) (Y>Z>X)
cout<<"this is the middle number "<<Y<<endl;
else
cout<<"either there are two numbers of equal value or you entered an invalid input";
system("pause");
return 0;
}
i tested it with using just
if (Z>X>Y) (Y>X>Z)
cout<<"this is the middle number "<<X<<endl;
however once ive addded the 'else if' statements the program said somethign was wrong and would not compile. i tested the else if with
#include<iostream>
using namespace std;
int main( ) {
char code;
cout << "Enter a marital code:\n";
cin >> code;
if (code =='M')
cout << " .. married\n"<<endl;
else if (code == 'S')
cout << " .. single\n"<<endl;
else if (code == 'D')
cout << " .. divorced"<<endl;
else
cout << " .. invalid coded entered.\n";
return 0 ;
}
and it worked perfectly. so what am i doing wrong with the first code?
any help would be great thanks.
-Leone