I am a beginner trying to learn the C-programming using VS 2012 Ultimate.
I just learned how to make a "Celsius-to-Fahrenheit" converter so I decided to take this further into "Volume of the sphere" calculator. This is what I have typed:
#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);
}
And when I try to compile this, I keep on getting error:
Error: Expected a ";" on float result_volume.
Where did I make the mistake and how can I fix this? Please help!
In the code you show, the ; is missing after
float volume /*Result of the calculation*/
It should be:
float volume; /*Result of the calculation*/
Note: When you get this kind of error, usually, you should look at the lines before the line where the error occurs. In your situation, this it is the previous line.
What happens is that the compiler only sees the issue when arriving at the ; on the next line. There, it realizes that the whole two lines don't make a single command and that a cut should occur somewhere. But it is incapable to tell where. So, it flags the error when it sees it, not where it actually occurs.
However, there have been significant improvements in that domain and, for instance, using Clang, the MAC OS X IDE Xcode is capable of accurately suggesting ; wherever there are needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With