// Listing 2.2 using std::cout
#include <iostream>
usingnamespace std;
int main ()
{
std::cout << "Hello there.\n";
std::cout << "Here is 5: " << 5 << "\n";
std::cout << "The manipulator std::end1 ";
std::cout << "writes a new line to the screen.";
cout << endl;
std::cout << "Here is a very big number:\t" << 70000;
cout << endl;
std::cout << "Here is the sum of 8 and 5:\t"
std::cout << (8+5) <<endl;
std::cout << "Here's a fraction:\t\t";
std::cout << (float) 5/8 << std::endl;
std::cout << "And a very very big number:\t";
std::cout << (double) 7000*7000 << std::endl;
std::cout << "Don't forget to replace jessy ";
std::cout << "with your name...\n";
std::cout << "jessy is a C++ programmer!\n";
return 0;
}
first of all remove the using namespace std you do not need that and std::
and then you will need to put std:: in front of the cout and endl's that do not have it in front. and your error is because on line 15 you are missing a semi-colon at the end...that is probably what your error message said. oh and btw 7k * 7k doesn't ahve any decimals so you probably don't need to make it a double. and on top of that doubles are 2x as precise as floats.
Thanks but now I have two errors. Im new to this.
// 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::end1 ";
std::cout << "writes a new line to the screen.";
std::cout << endl;
std::cout << "Here is a very big number:\t" << 70000;
std::cout << endl;
std::cout << "Here is the sum of 8 and 5:\t";
std::cout << (8+5) <<endl;
std::cout << "Here's a fraction:\t\t";
std::cout << (float) 5/8 << std::endl;
std::cout << "And a very very big number:\t";
std::cout << (double) 7000*7000 << std::endl;
std::cout << "Don't forget to replace jessy ";
std::cout << "with your name...\n";
std::cout << "jessy is a C++ programmer!\n";
return 0;
}
with errors:C:\Dev-Cpp\program.cpp:12: error: `endl' undeclared (first use this function)
C:\Dev-Cpp\program.cpp:12: error: (Each undeclared identifier is reported only once for each function it appears in.)
lines 7 , 9 , and 11 are supposed to be std::endl; and not endl;
Btw std::endl; is the same as '\n' << std::flush; and I think you should end the outputs with std::flush; and not just a semicolon where you are not using endl; but most compilers will automatically flush it anways.