1 2 3 4 5 6 7 8 9 10 11
|
#include <iostream>
using namespace std;
int main()
{
const float pi = 3.14;
float centimeters, radius = 11, sphere_volume = (4/3)*pi*(radius*radius*radius), surface_area = 5*pi*radius;
cout << "Volume = " << sphere_volume <<endl;
cout << "Area = " << surface_area <<endl;
cin.get ();
return 0;
}
|
This should perform correctly. Your idea behind your program was good, and you only had syntax errors. I didn't see totally wrong, but so you remember not to do them again, here they are.
1) comment syntax is
/* comment */
anything between the slash and star are discarded by the compiler. this is a block comment.
2) You need to the line "using namespace std;" after the header file <iostream>. this tells the compiler that you are using the standard input and output procedures.
3) You have forgotten some ";". They tell the compiler that the statement is over. This is extremely important, and the most common error, and I do it too xD.
Other then that, you did excellent.
I added a couple things to spice up your program.
You can do multiple declarations by separating your variables with commas.
Ex. type var1, var2, var3;
int weight, height;
You can also initialize the variables by separating them with commas too.
ex. type var1 = 0, var 2 =1, var3 = 999;
int height = 62, weight = 90;
At the end of your cout <<""; statement you may have noticed the <<endl; This just gives a new line to the console.
cin.get ();
is a function you use with strings, but without any parameters, it just waits for a key to be pressed.
Good work, keep it up.
maeriden has the same point, and since he has more experience, take advice from him! xD