|
-
Jun 11th, 2001, 05:13 PM
#1
Thread Starter
Member
Rookie Question
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
-
Jun 11th, 2001, 05:17 PM
#2
Frenzied Member
Code:
if(variable1 = 1) {
//code
}
elseif(variable1=2) {
//code
}
-
Jun 11th, 2001, 05:35 PM
#3
Frenzied Member
Steve
will always be true because you are asigning 1 to variable. You should use
-
Jun 11th, 2001, 05:37 PM
#4
Frenzied Member
And BloodMachine34 , to get a value ino a var use
Code:
#include <iostream>
usung namespace std;
int variable;
cin>>variable;
...
if(variable == 1)
//do sth
-
Jun 11th, 2001, 07:38 PM
#5
Thread Starter
Member
Cmon, I'm new to C++ but I'm not that stupid
-
Jun 12th, 2001, 04:25 AM
#6
-
Jun 16th, 2001, 02:52 PM
#7
answer to rookie question
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|