语法错误:意外的celsfah,期望(

huangapple go评论109阅读模式
英文:

syntax error: unexpected celsfah, expecting (

问题

你好,我有一个问题,我搜索了但没有找到解决方案。你能帮我吗?

  1. if choix != 1 && choix != 2 {
  2. fmt.Println("你没有输入正确的数字!")
  3. continueProg=true
  4. } else if choix == 1 {
  5. celsfah()
  6. fmt.Println("摄氏度")
  7. } else {
  8. //FahCels()
  9. fmt.Println("华氏度")
  10. }

我尝试了几种解决方案,但都没有成功。

函数Celsfah

  1. func celsfah(fahrenheit) {
  2. celsius := 0
  3. fahrenheit := 0
  4. fmt.Println("输入一个要转换为华氏度的摄氏度温度:")
  5. fmt.Scanln(&celsius)
  6. fahrenheit = celsius*1.8+32
  7. fmt.Println(&fahrenheit)
  8. }
英文:

Hello I have a problem i searched but i didn't find the solution.
Can you help me please ?

  1. if choix != 1 && choix != 2 {
  2. fmt.Println("you don't put a correct number!")
  3. continueProg=true
  4. } else if choix == 1 {
  5. celsfah()
  6. fmt.Println("Celsius")
  7. } else {
  8. //FahCels()
  9. fmt.Println("Fahrenheit")
  10. }

I tried several solutions but none worked

The Function Celsfah

  1. func celsfah(fahrenheit) {
  2. celsius := 0
  3. fahrenheit := 0
  4. fmt.Println("Entrer une température en Celsius à convertir en Fahrenheit : ")
  5. fmt.Scanln(&celsius)
  6. fahrenheit = celsius*1.8+32
  7. fmt.Println(&fahrenheit)
  8. }

答案1

得分: 1

我稍微简化了你的代码,并修复了一些问题,使其成为一个可运行的程序。主要问题包括:

  • celsfah() 函数中的参数是不必要的。
  • 最后的 Println() 语句打印的是 fahrenheit 的指针而不是值。
  1. package main
  2. import (
  3. "fmt"
  4. )
  5. func main() {
  6. choix := 1
  7. if choix != 1 && choix != 2 {
  8. fmt.Println("你没有输入正确的数字!")
  9. } else if choix == 1 {
  10. celsfah()
  11. fmt.Println("摄氏度")
  12. } else {
  13. //fahcels()
  14. fmt.Println("华氏度")
  15. }
  16. }
  17. func celsfah() {
  18. celsius := 0.0
  19. fahrenheit := 0.0
  20. fmt.Println("请输入一个摄氏温度,以转换为华氏温度:")
  21. fmt.Scanln(&celsius)
  22. fahrenheit = celsius*1.8 + 32
  23. fmt.Println(fahrenheit)
  24. }

希望对你有帮助!

英文:

I've simplified your code a bit and fixed some issues to turn it into a running program. The main issues were:

  • parameter into celsfah() unnecessary
  • the final Println() statement was printing the pointer to fahrenheit instead of the value

`

  1. package main
  2. import (
  3. "fmt"
  4. )
  5. func main() {
  6. choix := 1
  7. if choix != 1 && choix != 2 {
  8. fmt.Println("you didn't put in the correct number!")
  9. } else if choix == 1 {
  10. celsfah()
  11. fmt.Println("Celsius")
  12. } else {
  13. //fahcels()
  14. fmt.Println("Fahrenheit")
  15. }
  16. }
  17. func celsfah() {
  18. celsius := 0.0
  19. fahrenheit := 0.0
  20. fmt.Println("Enter a temperature in Celsius to convert to Fahrenheit: ")
  21. fmt.Scanln(&celsius)
  22. fahrenheit = celsius*1.8 + 32
  23. fmt.Println(fahrenheit)
  24. }

`

huangapple
  • 本文由 发表于 2017年2月17日 01:34:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/42280978.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定