Thread: trying if statement in the tutorial and stumble a problem

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    8

    trying if statement in the tutorial and stumble a problem

    I was doing the example in the tutorial and When I tried to run the program I got few error. Some of them I do not understand such as the file and directory is not there. cin is not identified. It also said there an error on iostream. I am using the compiler that this site directed me.(codeblock VB 2005/08) I really appreciate any feedback.

    Code:
    
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
       int age;
    
       cout<<"Please enter your Age";
       cin >>age;
       cin.ignore ();
    
       if ( age< 100)(
      cout<<"You are pretty young!\n";
      )
      else (age ==100)(
         cout<<"You are really old\n";
    )
    cin.get();
    }
    ,

    Code:
    
    C:\Users\gameffect\Documents\first1\if statements.c|1|error: iostream: No such file or directory|
    C:\Users\gameffect\Documents\first1\if statements.c|3|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'|
    C:\Users\gameffect\Documents\first1\if statements.c||In function 'main':|
    C:\Users\gameffect\Documents\first1\if statements.c|9|error: 'cout' undeclared (first use in this function)|
    C:\Users\gameffect\Documents\first1\if statements.c|9|error: (Each undeclared identifier is reported only once|
    C:\Users\gameffect\Documents\first1\if statements.c|9|error: for each function it appears in.)|
    C:\Users\gameffect\Documents\first1\if statements.c|10|error: 'cin' undeclared (first use in this function)|
    C:\Users\gameffect\Documents\first1\if statements.c|14|error: expected ')' before ';' token|
    C:\Users\gameffect\Documents\first1\if statements.c|16|error: expected ';' before 'else'|
    ||=== Build finished: 8 errors, 0 warnings ===|
    Last edited by abrofunky; 02-11-2012 at 08:18 AM. Reason: add proj

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > C:\Users\gameffect\Documents\first1\if statements.c
    You need to name your source files to end in .cpp, if you want to compile them as C++ programs.

    What you're seeing is 'C' complaining about things it doesn't know about.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    you use curly braces not ( ) to outline blocks, and you should have else if (..)
    Last edited by rogster001; 02-11-2012 at 08:41 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  4. #4
    Registered User
    Join Date
    Feb 2012
    Posts
    8

    solved my problem

    When I run it it says this on there
    Code:
    "ch2 - Debug" uses an invalid compiler. Probably the toolchain path within the compiler options is not setup correctly?! Skipping...

    I figure out my last problem but a new one occured. I would appreciate it for any help
    Last edited by abrofunky; 02-11-2012 at 10:43 PM. Reason: add txts

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Can you create a new C++ console project, and copy/paste your code into a new source file inside the new project?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Did you mess around with any of the options when you ran the Codeblocks installer? You should go to the global compiler/debugger screen and see what is currently set as the debugger, you should be able to navigate to mingw/bin/gdb.exe and select that if it is not already set. (The path will be something like that, I am just guessing right now)
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    FYI: The debugger used by Code::Blocks in supporting Visual Studio in the command line program that needs downloaded/installed separately from the VS Compiler.

    I think this link is to the correct tool; but, I am not sure.
    About Debugging Tools for Windows

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #8
    Registered User
    Join Date
    Feb 2012
    Posts
    8
    I really appreciate the help this forum has been help in proceeding in my programming. Keep it up members!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pls help with this tutorial problem
    By pelisa in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2010, 11:47 AM
  2. Stumble ...
    By twomers in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-23-2006, 08:20 PM
  3. Incorrect statement in the tutorial
    By Okiesmokie in forum C Programming
    Replies: 1
    Last Post: 08-25-2006, 03:42 AM
  4. Problem with Tutorial #2
    By Keiyentai in forum Windows Programming
    Replies: 2
    Last Post: 03-20-2005, 06:38 PM
  5. Stumble upon #ifndef
    By Zahl in forum C++ Programming
    Replies: 5
    Last Post: 02-05-2003, 12:17 PM