• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

c++ without fear HELP

 
Greenhorn
Posts: 4
Windows Vista Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, i think i'm doing something stupid but i can't see what i'm doing wrong, heres my problem

on example 1.1 of C++ without fear, edition 2

i'm using dev-c++ 4.9.8.0 and i do everthing it asks me but when i add a new project, the code in main.cpp does'nt match what the book says:

what i'm getting:


what it should be


i try to continue by adding the line " cout << "Never fear, C++ is here!"; " in between int main and system("PAUSE"), like the book tells me to but when the program is complied it doesn't work
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would have thought both code fragments were valid and equivalent to each other. The compiler is indifferent to whether the { is on a line by itself or not. Some people (myself included) think {s and }s should be on a line to themselves. It may be that your IDE has been set up to move { and } to lines by themselves. Can’t remember that from dev-c++, which I haven’t used for a long time, but I liked it when I used it.
system("PAUSE"); is unnecessary in some locations, and you may have to remove it if you are running from the command line.

It does, however, matter whether the { is before or after bits of code. So if you have got the cout line on the wrong side of a {. or even lost the { altogether, you will introduce an error into the code.

And welcome to the Ranch
 
daniel bailie
Greenhorn
Posts: 4
Windows Vista Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first off, sorry, there wasn't actually a problem at all. it was all a result of my brain not being able to read at 2 in the morning. the output of the program was "Never fear, C++ is here!Press any key to continue . . .", and i only read the press any key part., i completely fail sometimes

and thank you it very nice to be here
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You’re welcome
I had presumed the one missing ; was caused by your copying wrongly. Always use copy-and-paste.
There is some way to print a new line; you follow the "C++ is brilliant" bit by << and something else ;

Try std::endl or endl for end line. I found that here.
 
reply
    Bookmark Topic Watch Topic
  • New Topic