C++ killing me

Started by
7 comments, last by Thallid 14 years, 7 months ago
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 :(
Advertisement
What do you think the int() before your main function is for?
If i take it out, which makes sense, it still gives the error on line 10
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().

"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]

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/
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
Moved to For Beginners.
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.
It is working now, thank you to everyone for your help/links.

This topic is closed to new replies.

Advertisement