Sign in to follow this  
Thallid

C++ killing me

Recommended Posts

I am a noob at C++ my first assignment is to make a program to calculate the volume of a cone given it's diameter and height. This is what I wrote: #include <iostream> #include <cmath> using namespace std; float height(); float diameter(); int () int main () { const float pi = 3.14159; float height; float diameter; cout << "Please enter the height of the cone: "; cin << height; cout << "Please enter the diameter of the cone: "; cin << diameter; cout << "The volume of the cone is: " << 1.0/3.0 * pi * pow(1.0/2.0 * diameter,2) * height << ".\n"; return 0; } and these are my errors volumeofcone.cpp(8) : error C2059: syntax error : ')' volumeofcone.cpp(10) : error C2447: '{' : missing function header (old-style formal list?) I'm sorry to bother you guys, but I just feel like shoving a toothpick in my ear :(

Share this post


Link to post
Share on other sites
You seem to be getting functions and variables mixed up, we don't give people answers to their assignments here on gamedev, but we can give you the means in which to find a solution to your problem. In this case, you need to research variables and functions and clearly define their difference.

functions
http://www.cplusplus.com/doc/tutorial/functions/

variables
http://www.cplusplus.com/doc/tutorial/variables/

Share this post


Link to post
Share on other sites
Hello ... as SiCrane said , you have to take out the int() . Also it is cin >> not cin <<. After making these two changes I was able to compile your code without errors.

Even though these are valid lines, I don't see their purpose so you can take them out as well:
float height();
float diameter();

-------------------------------------------------------------------------------------------
My Website - Portfolio, Tutorials
My blog

Share this post


Link to post
Share on other sites
Quote:
Original post by Thallid
I am a noob at C++
my first assignment is to make a program to calculate the volume of a cone given it's diameter and height. This is what I wrote:

#include <iostream>
#include <cmath>
using namespace std;

float height();
float diameter();

int ()
int main ()
{
const float pi = 3.14159;
float height;
float diameter;

cout << "Please enter the height of the cone: ";
cin << height;
cout << "Please enter the diameter of the cone: ";
cin << diameter;
cout << "The volume of the cone is: " << 1.0/3.0 * pi * pow(1.0/2.0 * diameter,2) * height << ".\n";
return 0;
}

and these are my errors

volumeofcone.cpp(8) : error C2059: syntax error : ')'
volumeofcone.cpp(10) : error C2447: '{' : missing function header (old-style formal list?)

I'm sorry to bother you guys, but I just feel like shoving a toothpick in my ear :(


1) Why are you declaring the functions "float height();" and "float diameter();"? You have no definitions for them, and you don't try to use them.
2) "int ()" is completely useless
3) "const float pi = 3.14159;" should be "const float pi = 3.14159f;", although this is just a nit-pick.
4) When you declare the "float height;" and "float diameter;" variables, their names conflict with the previously declared "height" and "diameter" functions above (see point 1).
5) "cin" and "cout" do not use the same arrow operators. Use "<<" for cout and ">>" for cin.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this