|
-
Apr 22nd, 2001, 09:11 PM
#1
Thread Starter
Hyperactive Member
how to do u use greater than or less than signs with switch and case statements?
case > 5
case < 5
i'm using that but that obviously doesn't work
Bababooey
Tatatoothy
Mamamonkey
-
Apr 23rd, 2001, 05:08 AM
#2
Frenzied Member
I think it's easier with if statements, but try this:
Code:
switch(a)
case a > 5:
//do something
break;
-
Apr 23rd, 2001, 05:17 AM
#3
Frenzied Member
Use this instead:
Code:
#include <iostream.h>
void main()
{
int a;
int b;
cout <<"Value for a: ";
cin>>a;
cout<<"Value for b: ";
cin>>b;
if(a > b)
cout<<"a is greater than b"<<endl;;
if (a < b)
cout<<"a is lesser than b"<<endl;
if (a == b)
cout<<"a and b are equal"<<endl;
}
-
Apr 23rd, 2001, 07:22 AM
#4
Thread Starter
Hyperactive Member
the if is definitely easier but i have to use a switch
statement as part of an assignment.
Bababooey
Tatatoothy
Mamamonkey
-
Apr 23rd, 2001, 04:08 PM
#5
Thread Starter
Hyperactive Member
thx harry but i'm very familiar with case statements, what i wanted to accomplish, however, was to compare the switch against another number
similar to this in VB:
[CODE
case is < 5:
case is > 5:
[/CODE]
Bababooey
Tatatoothy
Mamamonkey
-
Apr 23rd, 2001, 05:06 PM
#6
Frenzied Member
I know what you want, but what I'm saying is that you can't use expressions with variable results in a switch statement. No two cases can evaluate to the same result. There is no 'case Is < 5' style solution.
I know you said that you have to use switch statements in the assignment, but isn't there anywhere else you could us a switch statement? This seems like an inappropriate situation for one.
Harry.
"From one thing, know ten thousand things."
-
Apr 24th, 2001, 06:48 AM
#7
case 1:
case 2:
case 3:
case 4: code here
break
-
Apr 24th, 2001, 03:29 PM
#8
Addicted Member
I think of this..
Code:
int y=45;
switch(y>5)
{
case 0:
printf("Y is less than or equal to 5");
break;
case 1:
printf("Y is Greater than 5");
break;
default:
}
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
|