Jump to content
  • Advertisement
Sign in to follow this  
Thallid

C++ killing me

This topic is 3330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Take out the float height(); and float diameter(); lines. It looks like you are declaring 2 functions you aren't using and then your also making 2 variables of the same name inside of main().

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!