大于和小于switch语句C [英] Larger than and less than in switch statement C

查看:1444
本文介绍了大于和小于switch语句C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个有很多比较的代码

I'm trying to write a code that has a lot of comparison


Write a program in "QUANT.C" which "quantifies" numbers.  Read an integer "x" and test it, producing the 
following output: 

x greater than or equal to 1000 print "hugely positive" 
x from 999 to 100 (including 100) print "very positive" 
x between 100 and 0 print "positive" 
x exactly 0 print "zero" 
x between 0 and -100 print "negative" 
x from -100 to -999 (including -100) print "very negative" 
x less than or equal to -1000 print "hugely negative" 

Thus -10 would print "negative", -100 "very negative" and 458 "very positive".

然后我尝试使用开关来解决它但是它不起作用,我是否必须使用if语句解决它或者有一个使用开关来解决它的方法?

then I tried to solve it using switch but it didn't work, do I have to solve it using if statement or there is a method to solve it using switch?


推荐答案

没有干净的方法用switch来解决这个问题,因为案例需要是整数类型。看看if-else if-else。

There is no clean way to solve this with switch, as cases need to be integral types. Have a look at if-else if-else.

这篇关于大于和小于switch语句C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆