This is what i have so far and i must only use the single selection form of the if statement, i tried everything.
if ((num1>num2)&&(num1>num3))
{
{ cout<< "Number one is the Largest which is: "<<num1<<endl;
if ((num2>num1)&&(num2>num3))
cout<< "Number two is the largest which is: "<<num2<<endl;
if ((num3>num1)&&(num3>num2))
cout<< "Number three is the largest which is: "<<num3<<endl;
}
}
{
if ((num2<num1)&&(num2<num3))
cout<< "Number two is the smallest which is: "<<num2<<endl;
if ((num3<num1)&&(num3<num2))
cout << "Number three is the smallest which is: " <<num3<< endl;
if ((num1<num2)&&(num1<num3))
cout<< "Number one is the smallest which is: "<<num1<<endl;
}
int a, b, c, d;
cout << "enter the value of a: ";
cin >> a;
cout << "enter the value of b: ";
cin >> b;
cout << "enter the value of c: ";
cin >> c;
d = ((a > b) ? a : b);
cout << "the largest of all is: " << ((d > c) ? d : c) << endl;
Don't just post solutions; the TC won't learn anything that way. And in any case, that isn't using if statements, as the TC specifically said they had to.
ok here is the problem write a program that inputs 2 different intgers from the keyboard, then prints the sum, the average, the product, the smallest an the largest of these numbers. Use only the single selection form of the if statment. The only problem i'm having is using the single if statment part
Use only the single selection form of the if statement
This does not mean you may only use 'if' once. It means only use 'if {}', do not use 'if {} else {}'. You are already using the correct form in your code. The problem is that your code is just wrong. You should use indenting, so that you can see what you're doing. Here is your code again, but with indenting:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
if ((num1>num2)&&(num1>num3))
{
{ cout<< "Number one is the Largest which is: "<<num1<<endl;
if ((num2>num1)&&(num2>num3))
cout<< "Number two is the largest which is: "<<num2<<endl;
if ((num3>num1)&&(num3>num2))
cout<< "Number three is the largest which is: "<<num3<<endl;
}
}
{
if ((num2<num1)&&(num2<num3))
cout<< "Number two is the smallest which is: "<<num2<<endl;
if ((num3<num1)&&(num3<num2))
cout << "Number three is the smallest which is: " <<num3<< endl;
if ((num1<num2)&&(num1<num3))
cout<< "Number one is the smallest which is: "<<num1<<endl;
}
Can you see now that you will never test for number two or number three being largest unless number one is the largest? You have your tests for number two and number three being largest inside the code that runs if number one is largest.
I'm sorry for my bad english and for the scene but unfortunately i'm rikiwife's teacher.
rikiwife you choose the easiest solution i'm... very disappointed... but not surprised.
Not only i'm disappointed of you choosing to cheat but because you chose to cheat on the easiest exam case.
As I'm very very very very very very very very very disappointed about you taking the others for shit, trying to manipulate them and to make fun on the others work (mine but especially your fellow comrades) :
Now you got a 5 points penalty on your semester grade. Hope you like it already.
You have one week to change for another exam case and compensate. So to say you have to mail me.
You really should since this one, the easiest project subject, only permitted to have 10/20.
10 less 5 = 5.
Do your maths again young man.
You really need to wake up young man !
You have my e-mail, i'm waiting for answers and for your new subject request.You should really take that chance, because if you present a code with elements on this page I'm afraid you may have to come back in June, to take again the exam, etc... not really fun, uh ?
Plus June extra session is really, really, really harder since none of the students that had to take the extra exam session had had it passed.
Plus a an IT student you should be able to code a bit, don't you ?
Interesting. Call me crazy but unless that user name identifies you to your teacher, there is no way I would email an admittance of guilt. It might be a clever trap.
Anyway, check this out:
1 2 3 4 5 6 7
int num1, num2, num3;
//...
using std::cout;
using std::min;
using std::max;
cout << max( max( num1, num2 ), num3 );
cout << min( min( num1, num2 ), num3 );
Im not paying cmt2011 because he/she is not my teacher and they got some info wrong im not a male hence the name "rikiwife" so i dont know wats wrong with that person, so go get a life cmt2011