Click to See Complete Forum and Search --> : Rookie Question
BloodMachine34
Jun 11th, 2001, 05:13 PM
How do I use the if...elseif...elseif...else statements?
For example a program asks you what you want to do. If you press 1, 2 numbers will be added, if you press 2, the numbers will be subtracted, if you press 3 the numbers will be multiplied, and 4 is division. Thanks
SteveCRM
Jun 11th, 2001, 05:17 PM
if(variable1 = 1) {
//code
}
elseif(variable1=2) {
//code
}
Vlatko
Jun 11th, 2001, 05:35 PM
Steve
if(variable1 = 1)
will always be true because you are asigning 1 to variable. You should use
if(variable1 == 1)
Vlatko
Jun 11th, 2001, 05:37 PM
And BloodMachine34 :confused: , to get a value ino a var use
#include <iostream>
usung namespace std;
int variable;
cin>>variable;
...
if(variable == 1)
//do sth
BloodMachine34
Jun 11th, 2001, 07:38 PM
Cmon, I'm new to C++ but I'm not that stupid ;)
Vlatko
Jun 12th, 2001, 04:25 AM
:cool: Sorry Man :cool:
skara_B
Jun 16th, 2001, 02:52 PM
if(yaddayadda==number)
{your code about adding or whatever
}
else
{your code about multiplying or whatever
}
You can also state two times if in a row if you want to, but I think you always have to end an else.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.