So, recently deciding that I want try and learn C++, I picked up "Teach Yourself C++ in 24 Hours" for a starting point. All works well, until Hour 2 ( ) where I come to a problem - I type in the code exactly as it is in the book, compile it, and when I run the program, the output is different than what is shown in the book.
Here is the code:
Code:
#include <iostream>
int Add (int x, int y)
{
std::cout << "In Add(), recieved " << x << " and " << y << "\n";
return (x+y);
}
int main()
{
std::cout << "I'm in main()!\n";
std::cout << "\nCalling Add() \n";
std::cout << "The value returned is: " << Add(3,4);
std::cout << "\nBack in main().\n";
std::cout << "\nExiting...\n\n";
return 0;
}
Here is what is supposed to come out:
I'm in main()!
Calling Add()
In Add(), received 3 and 4
The value returned is: 7
Back in main().
Exiting...
And, finally, here is what I get:
Calling Add()
The value returned is: In Add(), received 3 and 4
7
Back in main().
Exiting...
A few notes - I use Mac OS X 10.4.6, write the code in Xcode, and use the Terminal to compile. I thought maybe the output was different because I am running OS X, but that does not make any sense to me. I have read the code over and over, just to make sure I typed everything correctly.
Sorry for the long post, and not sure if I broke any rules by posting code on here, if I did, just left me know. Any help at all on this issue would be greatly appreciated!
Thanks,
~eros