Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BlackBlade

macrumors member
Original poster
Jan 4, 2010
42
0
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
Code:
#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)
 
Last edited by a moderator:

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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

macrumors member
Aug 8, 2011
48
0
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

macrumors member
Original poster
Jan 4, 2010
42
0
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

macrumors 68040
Feb 2, 2008
3,551
79
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

macrumors member
Original poster
Jan 4, 2010
42
0
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

macrumors member
Aug 8, 2011
48
0
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

macrumors 68040
Feb 2, 2008
3,551
79
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

macrumors member
Original poster
Jan 4, 2010
42
0
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

macrumors 68040
Feb 2, 2008
3,551
79
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.