Log in

View Full Version : Whats wrong with this code?


Dragon Keeper
06-08-2004, 01:46 PM
Whats wrong with this code, it tells me there are 5 errors but I got it straight out of a book...btw I'm using visual C++ 6.0

// Listing 2.2 using std::cout
#include <iostream>
int main()
{
std::cout << "Hello there.\n";
std::cout << "Here is 5: " << 5 << "\n";
std::cout << "The manipulator std::endl ";
std::cout << "Writes a new line to the screen.";
std::cout << std::endl;
std::cout << "Here is a verry big number:\t" << 70000;
std::cout << std::endl;
std::cout << "Here is the sum of 8 and 5:\t";
std::cout << 8+5 << std::endl;
std::cout << "Here's a fraction:\t\t";
std::cout << (float) 5\8 << std::endl;
std::cout << "And a verry big number:\t";
std::cout << (double) 7000 * 7000 << std::endl;
std::cout << "Don't forget to replace jesse liberty";
std::cout << "With your name...\n"
std::cout << "Joth Colgrove is a c++ programmer!\n";
return 0;
}

gfm
06-08-2004, 01:51 PM
5\8 should be 5/8 (division operator is /)

Missing a semicolon on the next to last output line.

Other than that it looks fine, but beware that Visual C++ 6.0 didn't have the greatest support for the C++ standard library, so you might run into issues that really aren't with it.. though in an example this simple, probably not...

Dragon Keeper
06-08-2004, 01:54 PM
thats better, just a stupid mistake I made I guess.

PalmTree
06-08-2004, 06:41 PM
Whats wrong with this code?
It's C++

PalmTree
06-08-2004, 06:42 PM
Sorry, couldn't resist :D

PeterM
06-09-2004, 03:22 AM
Hmm, I wonder why in some lines there are "\n" characters and in others there are "std::endl"s?

I dislike this inconsistency!

</anal>

tjones
06-11-2004, 07:08 AM
\n and std::endl do not behave the same.

std::endl flushes the output queue. \n behaves like any other character.