错误:缺少“;”

3

我是一个初学者,试图使用VS 2012 Ultimate学习C编程。

我刚刚学会了如何制作一个“摄氏度转华氏度”的转换器,所以我决定将其进一步发展为“球体体积”计算器。这就是我输入的内容:

#include <stdio.h>
#include <string.h>

char line[100]; /*Line input by the user*/
char line_2[100]; /*Second line input by the user*/
float radius; /*Value of the radius input by the user*/
float pi; /*Value of the pi input by the user*/
float volume /*Result of the calculation*/
float result_volume; /*Result of the second calculation*/
float result_volume2; /*Result of the third calculation*/
float result_volume3; /*Result of the fourth calculation*/

int main()
{
    printf("Please write the value of the radius: ");
    fgets(line,sizeof(line),stdin);
    sscanf(line,"%f",&radius);
    printf("Please write the value of the Pi ");
    fgets(line_2,sizeof(line_2),stdin);
    sscanf(line_2,"%f",&pi);
    volume = radius*radius*radius;
    result_volume = volume *pi;
    result_volume2 = result_volume*4;
    result_volume3 = result_volume2/3;
    printf("When the radius is %f, and the Pi, %f, then the volume of the sphere is: 
                %f\n", radius, pi, result_volume3);
    return (0);
}

当我尝试编译这个代码时,一直出现错误:
Error: Expected a ";" on float result_volume.

我做错了什么,怎么才能修改?请帮忙!

2个回答

4
在您提供的代码中,

后面缺少;
float volume /*Result of the calculation*/

应该是:

float volume; /*Result of the calculation*/

注意:当您遇到这种错误时,通常应查看发生错误的行之前的行。在您的情况下,它是上一行。
发生的情况是编译器只有在到达下一行的;时才会看到问题。在那里,它意识到整个两行不构成单个命令,必须在某个地方进行切割。但是,它无法确定切割的位置。因此,它在看到错误时标记错误,而不是实际出现错误的位置。
然而,在这个领域已经取得了显著的进展,例如使用Clang,MAC OS X IDE Xcode能够准确地建议在需要的任何地方使用;

0
float volume /*Result of the calculation*/
float result_volume; /*Result of the second calculation*/

您忘记在float volume后面加上分号(;)。
float volume; /*Result of the calculation*/
float result_volume; /*Result of the second calculation*/

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接