我是一个初学者,试图使用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.
我做错了什么,怎么才能修改?请帮忙!