我是一名尝试使用 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.
我在哪里犯了错误,我该如何解决?请帮忙!