在C语言中不断收到错误消息它们是什么意思?

在C语言中不断收到错误消息它们是什么意思?,c,cs50,C,Cs50,有人能给我解释一下这些错误消息是什么意思吗?我一直收到“错误:在顶级声明之后应该是“;”和“应该是标识符或“(”).我对编程非常陌生,不懂任何建议,敬请谅解。我的程序编码是否正确?其目的是检查用户输入的边是否形成三角形。以下是我的代码: #include <cs50.h> #include <stdio.h> bool check_triangle(float x, float y, float z); int main(void) { printf(&quo

有人能给我解释一下这些错误消息是什么意思吗?我一直收到“错误:在顶级声明之后应该是“;”和“应该是标识符或“(”).我对编程非常陌生,不懂任何建议,敬请谅解。我的程序编码是否正确?其目的是检查用户输入的边是否形成三角形。以下是我的代码:

#include <cs50.h>
#include <stdio.h>
bool check_triangle(float x, float y, float z);
int main(void)

{
     printf("what is the length of the first side of the triangle: ");
     float x = get_float();
     printf("what is the length of the second side of the triangle: ");
     float y = get_float();
      printf("what is the length of the third side of the triangle: ");
     float z = get_float();
    
bool check_triangle(float x, float y, float z);
    if
        {
            (x <= 0 || y <= 0 || z <= 0)
            return false;
        }
    if  
         {
            ( x+ y <= z || x +  <= y || y + z <= x)
             return false;
         }
    return true
}
#包括
#包括
布尔检查_三角形(浮动x、浮动y、浮动z);
内部主(空)
{
printf(“三角形第一边的长度:”);
float x=get_float();
printf(“三角形第二条边的长度:”);
float y=get_float();
printf(“三角形第三边的长度:”);
float z=get_float();
布尔检查_三角形(浮动x、浮动y、浮动z);
如果
{

(x在学习C语言的过程中,语法有几个方面你都在苦苦挣扎。首先,C语言不允许嵌套函数。虽然
main()
缺少一个结尾
可能解释了部分问题——看起来你是在尝试在
main()的内部定义
check_triangle()
——那不行

接下来,除非函数太长,不能简单地将其放在
main()
上方而不完全弄乱文件,否则请忘记尝试在
main()
上方提供函数原型以及下面的定义——您可以稍后再做


在您的测试中,
x+下面是我在代码中发现的几个错误

  • 缺少
    main
    的右大括号
    }
  • 在函数减速中
    bool check_三角形(float x,float y,float z);
    不需要分号,并且缺少开口撑杆
    {
  • if
    中,条件应该是
    if(您的条件)
    ,而不是
    if{}

  • x+从修正缩进开始。这会帮助你指出正确的方向。我现在就做!为什么你有一个悬空的
    main
    ?另外
    检查\u三角形
    缺少结束
    }
    。您甚至没有正确的基本语法。您的函数在main中。您在函数声明之后有
    ,但随后您继续编写函数体。如果
    条件在
    之后,则{
    。别再往墙上扔东西了,希望有东西能粘在墙上。重温你的课程/书籍的导论章节,试着一次复制一个简单的例子。随机编写代码,然后问问题,这不会让你有任何进展。@alext1863我知道从0开始学习可能会让人望而生畏。这就是你为什么要这么做的原因一次应该做一件事。只要用一个
    if
    写一个非常简单的程序就行了。只要在
    main
    中用一个
    if
    就行了。正确后,用一个非常简单的函数写一个非常非常简单的程序-不
    if
    没有别的。一次攻击一件事。这确实帮助清除了一些漏洞谢谢你花了这么多的时间和你在这方面所做的细节,我真的很感激。很高兴能帮上忙。C有很多东西要学,所以把它想象成一次旅行而不是一场比赛。给自己一年(不是一学期)在你能够真正流利地掌握C语言的核心内容之前,你永远都不会讲到最后。你学习C语言就像吃鲸鱼一样——一次一个字节。
    :)
    祝你的编码好运!确保你也看了一遍。给时间添加其他答案,但当你对答案满意时,选择一个。
    bool check_triangle (float x, float y, float z) {
        
        if (x <= 0. || y <= 0. || z <= 0.) {
            return false;
        }
        
        if ( x + y <= z || x + z <= y || y + z <= x) {
            return false;
        }
        
        return true;
    }
    
        float x = get_float("Length of the first side of the triangle: ");
        
        float y = get_float("Length of the second side of the triangle: ");
        
        float z = get_float("Length of the third side of the triangle: ");
    
        if (check_triangle (x, y, z)) {
            puts ("\nyou have a triangle");
        }
        else {
            puts ("\nnot a triangle");
        }
    
    #include <cs50.h>
    #include <stdio.h>
    
    bool check_triangle (float x, float y, float z) {
        
        if (x <= 0. || y <= 0. || z <= 0.) {
            return false;
        }
        
        if ( x + y <= z || x + z <= y || y + z <= x) {
            return false;
        }
        
        return true;
    }
    
    int main (void) {
        
        float x = get_float("Length of the first side of the triangle: ");
        
        float y = get_float("Length of the second side of the triangle: ");
        
        float z = get_float("Length of the third side of the triangle: ");
        
        if (check_triangle (x, y, z)) {
            puts ("\nyou have a triangle");
        }
        else {
            puts ("\nnot a triangle");
        }
    }
    
    gcc -Wall -Wextra -pedantic -Wshadow -std=c11 -Ofast -o checktriangle checktriangle.c -lcs50
    
     #include <cs50.h>
    
     #include <stdio.h>
    
     bool check_triangle(float x, float y, float z);
    
     int main(void)
     {
           float x, y, z;
    
           printf("what is the length of the first side of the triangle: \n");
           x = get_float();
           printf("what is the length of the second side of the triangle: \n");
           y = get_float();
           printf("what is the length of the third side of the triangle: \n");
           z = get_float();
    
           if(check_triangle(x,y,z))
           {
                 printf("Check triangle is success\n ");
           }
           else
           {
                 printf("Check triangle failed\n ");
           }
           return 0;
       }
    
       bool check_triangle(float x, float y, float z)    
       {     
             if(x <= 0 || y <= 0 || z <= 0)
             {
                  return false;
             }
             if( x + y <= z || x + z  <= y || y + z <= x)
             {
                  return false;
             }
             return true;
         }