PDA

View Full Version : C++ #include help?




BlackBlade
Dec 5, 2011, 09:00 AM
ok never used C++ before and i am using it far a college corse and i decided to use Xcode 4 based on the suggestions made on this site, I watched a tutorial on how to generally use c++ and i am familiar with python, i am wondering why no #include commands work. i have gone through aprox. 30 pages on google looking for an answer

here is my code just in case

#include <cmath>


using manespace std;

int main(void)

(
double dnumber1 = 0.0;
double dnumber2 = 0.0;
double dnumber3 = 0.0;
double average = 0.0;

cout << "please enter 3 numbers: "; <<endl;

cin >> dnumber1;
cin >> dnumber2;
cin >> dnumber3;

daverage = (dmunber1 + dmunber2 + dnumber3) / 3;

cout << "the average of the mumbers are: " << daverage << endl << endl

system("pause")
return 0;

)

and fyi i have tried math, math.h and iostream (iostream is th most used one i can find but it is not recognized, it says "iostream" file not found)



subsonix
Dec 5, 2011, 09:13 AM
What kind of error messages do you get that is related to cmath? The posted code is full of errors not related to the inclusion of cmath. Also nothing in the program requires cmath so you can leave that out, but you will need iostream.

iHutch105
Dec 5, 2011, 09:17 AM
This isn't your exact code, is it?

I can see a lot of typos. Namespace spelled wrong, wrong kind of parenthesis for the function body and a couple of lines with missing terminators.

BlackBlade
Dec 5, 2011, 09:25 AM
What kind of error messages do you get that is related to cmath? The posted code is full of errors not related to the inclusion of cmath. Also nothing in the program requires cmath so you can leave that out, but you will need iostream.

cmath related errors are simply this, "cmath" file not found, and iostream is not recognized, i then went through the whole list of include functions(not sure what to call them) and the closest thing on there is IOsurface or IOsurface.h




This isn't your exact code, is it?

I can see a lot of typos. Namespace spelled wrong, wrong kind of parenthesis for the function body and a couple of lines with missing terminators.

this is my first time ever using C++ ever so yes this is my whole code, yet no errors occur or are shown except for the include statement (and i just noticed the typos my self and corrected them) also can u please elaborate on the parenthesis problem?

subsonix
Dec 5, 2011, 09:26 AM
cmath related errors are simply this, "cmath" file not found, and iostream is not recognized, i then went through the whole list of include functions(not sure what to call them) and the closest thing on there is IOsurface or IOsurface.h

Did you create a C++ project and not Objective-C or Cocoa? I you pick a Cocoa application you will get this error.

BlackBlade
Dec 5, 2011, 09:31 AM
Did you create a C++ project and not Objective-C or Cocoa? I you pick a Cocoa application you will get this error.

i am an idiot, i figured it out, i never made a file in the project i simply used main.m
just tried making a c++ file and it worked

thanks a lot, now i won't fail! thanks again

iHutch105
Dec 5, 2011, 09:32 AM
can u please elaborate on the parenthesis problem?

A function body should be contained in { } brackets, not ( ), which normally house the parameters for a functions.

So,

int main(void)
{
// Code here
}

I'm currently at work, so don't have my Mac at hand to identify and XCode specific issues, but I'm happy to look through this and give you a hand when I get home (probably 3 hours or so) if nobody else has done so by then.

subsonix
Dec 5, 2011, 09:34 AM
i am an idiot, i figured it out, i never made a file in the project i simply used main.m
just tried making a c++ file and it worked

thanks a lot, now i won't fail! thanks again

Good to hear, but you should not have a main.m file at all really. When you create a new project, pick "command line tool" then "C++".

BlackBlade
Dec 5, 2011, 09:38 AM
Good to hear, but you should not have a main.m file at all really. When you create a new project, pick "command line tool" then "C++".

thanks again, and now i can actually make a working program, i never knew to use the command line tool i just used the default (which i believe is empty application)

subsonix
Dec 5, 2011, 09:53 AM
thanks again, and now i can actually make a working program, i never knew to use the command line tool i just used the default (which i believe is empty application)

True, the default is set up for a Objective-C based Cocoa application, but you will be making a text based C++ application.

lights
Dec 13, 2011, 02:23 PM
brackets =)