Not a good idea to use doubles in switch statements because they are often inprecice due to the way they are stored in memory. If you really have to use switch instead of that if statement then you should multiply it by 100 then assigned the result to an integer. Be careful that you don't get data overflow errors doing that.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
> I know the if statement would be a better choice but I must you use the switch for an assignment
would this make your teacher happy?
enum { LESS_THAN_10000, NOT_LESS_THAN_10000 };
int to_be_used_in_switch = sales < 100000.0 ?
LESS_THAN_10000 : NOT_LESS_THAN_10000 ;
switch( to_be_used_in_switch )
{
case LESS_THAN_10000:
/* ... */ break ;
case NOT_LESS_THAN_10000:
/* ... */ break ;
default:
assert(false) ;
}
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287