Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
If statement 如果还有其他的话,请在go lang_If Statement_Go - Fatal编程技术网

If statement 如果还有其他的话,请在go lang

If statement 如果还有其他的话,请在go lang,if-statement,go,If Statement,Go,有人能帮我调试这个程序吗?每个输入只处理其他部分。 这是一个给学生评分的程序。学生输入分数并显示成绩 func main(){ var x int fmt.Println("Enter your marks") fmt.Scanf("%d",&x) if (100 <= x) && (x<=75){ fmt.Println("D1") }else if (74 <= x)&&(x

有人能帮我调试这个程序吗?每个输入只处理其他部分。 这是一个给学生评分的程序。学生输入分数并显示成绩

func main(){
    var x int
    fmt.Println("Enter your marks")

    fmt.Scanf("%d",&x)

    if (100 <= x) && (x<=75){
        fmt.Println("D1")
    }else if (74 <= x)&&(x <= 70){
        fmt.Println("D2")
    }else if (69 <= x )&&(x<=65){
        fmt.Println("C3")
    }else if (64 <= x)&&(x <= 60){
        fmt.Println("C4")
    }else if (59 <= x)&&(x <= 55){
        fmt.Println("C5")
    }else if (54 <= x)&&( x<= 50){
        fmt.Println("C6")
    }else if (49 <= x )&&(x<= 45){
        fmt.Println("P7")
    }else{
        fmt.Println("Work harder")
    }
}
func main(){
var x int
fmt.Println(“输入您的分数”)
格式扫描(“%d”和“x”)

如果(100你有逻辑问题

改变

if (100 <= x) && (x<=75){

最后一点注释:这种类型的切换代码很少出现,因为通常阈值和相关注释都是作为数据存储的,例如在IF语句中的
结构中:

if 100 is less than x (which means x has to be greater than 100)
AND
x less than (or equal to) 75
do this--

x永远不会大于100而小于75,所以它总是做其他的…

谢谢你的帮助。希望在将来的某个时候它能帮助其他人

包干管

导入“fmt”
func main(){
var x int
fmt.Println(“输入您的分数”)
格式扫描(“%d”和“x”)

if(75本规范中提供的所有if和if-else语句在逻辑上都不正确

例如:

 if (100 <= x) && (x<=75) 

嘎!
constant@BilltheLizard这种比较形式反映了数学符号
75@NickCraig-Wood我同意这样写更有意义,但我的眼睛不习惯,所以我的大脑没有正确解析它。:)@ BeleliZARD,你喜欢开关版本更好吗?我猜我们不习惯分析这些的原因是我们经常在数据中有所有的阀值,而不是常量直接在代码中间,我们循环……是的,看起来更自然。正如在另一个注释中所写的。不要混合<代码>常数。
if 100 is less than x (which means x has to be greater than 100)
AND
x less than (or equal to) 75
do this--
import "fmt"

func main(){
var x int
fmt.Println("Enter your marks")
fmt.Scanf("%d",&x)
if (75<= x) && (x<=100){
      fmt.Println("D1")
      }else if (70 <= x)&&(x <= 74){
       fmt.Println("D2")
      }else if (65 <= x )&&(x<=69){
      fmt.Println("C3")
      }else if (60 <= x)&&(x <= 64){
      fmt.Println("C4")
      }else if (55 <= x)&&(x <= 59){
      fmt.Println("C5")
      }else if (50 <= x)&&( x<= 54){
      fmt.Println("C6")
      }else if (45 <= x )&&(x<= 49){
      fmt.Println("P7")
      }else{
        fmt.Println("Work harder")
      }

      }
 if (100 <= x) && (x<=75) 
func main() {
    var x int
    fmt.Println("Enter your marks")

    fmt.Scanf("%d", &x)

    if (100 >= x) && (x >= 75) {
        fmt.Println("D1")
    } else if (74 >= x) && (x >= 70) {
        fmt.Println("D2")
    } else if (69 >= x) && (x >= 65) {
        fmt.Println("C3")
    } else if (64 >= x) && (x >= 60) {
        fmt.Println("C4")
    } else if (59 >= x) && (x >= 55) {
        fmt.Println("C5")
    } else if (54 >= x) && (x >= 50) {
        fmt.Println("C6")
    } else if (49 >= x) && (x >= 45) {
        fmt.Println("P7")
    } else {
        fmt.Println("Work harder")
    }