help im an idiot

This is a discussion on help im an idiot within the C++ Programming forums, part of the General Programming Boards category; please help me. this is my first day learning about programming and im stuck on lesson 2 of the online ...

  1. #1
    vex
    vex is offline
    Registered User
    Join Date
    Mar 2004
    Posts
    6

    help im an idiot

    please help me. this is my first day learning about programming and im stuck on lesson 2 of the online tuturial on this website. i havent done any courses or read any books yet. but when i go to do the example programme and compile it comes up with this error: [Warning] In function `int main()':
    `cout' undeclared (first use this function)
    (Each undeclared identifier is reported only
    `cin' undeclared (first use this function)
    even when i copy and paste the programme.

    the programme is this:
    Code:
    include <iostream.h>			
    int main()				//Most important part of the program!
    {
      int age;				//Need a variable...
      cout<<"Please input your age: ";	//Asks for age
      cin>>age;				//The input is put in age
      if(age<100)				//If the age is less than 100
      {
         cout<<"You are pretty young!";     //Just to show it works
      }
      else if(age==100)		//I use else just to show an example 
      {
         cout<<"You are old";		//Just to show you it works...
      }
      else
      {
        cout<<"You are really old";	//Executed if no other statement is executed
      }
      return 0;
    }

    your assistance wil be muchly appreciated
    thanks simon
    Last edited by vex; 03-13-2004 at 07:36 PM.

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    1
    what compiler are you using?
    try this

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()//Most important part of the program!
    {
      int age;//Need a variable...
      cout<<"Please input your age: ";//Asks for age
      cin>>age;//The input is put in age
      if(age<100)//If the age is less than 100
      {
         cout<<"You are pretty young!";     //Just to show it works
      }
      else if(age==100)//I use else just to show an example 
      {
         cout<<"You are old";//Just to show you it works...
      }
      else
      {
        cout<<"You are really old";//Executed if no other statement is executed
      }
      return 0;
    }
    Last edited by windalus; 03-13-2004 at 07:45 PM.

  3. #3
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    Only two things need to be changed:

    Code:
    #include <iostream> //Drop the .h
    
    using namespace std; //Gets rid of the "undeclared" errors
    
    int main()
    {
      //code
      cin.get(); //You may want to use this to pause your program
      return 0;
    }
    So, just dropping the .h and adding using namespace std; should fix it, and cin.get(); will pause it if you want.

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  4. #4
    WDT
    WDT is offline
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    's about time the tutorials on the site got updated or a link added to one that conforms to currents standards
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  5. #5
    vex
    vex is offline
    Registered User
    Join Date
    Mar 2004
    Posts
    6
    im using dev c++ 4.9.8.0 compiler. if i drop the .h from iostreasm and write in using namespace std then this messages appears
    5 C:\My Documents\Untitled2.cpp parse error before `int'
    8 C:\My Documents\Untitled2.cpp syntax error before `<<' token
    9 C:\My Documents\Untitled2.cpp syntax error before `>>' token
    In
    instantiated from here

  6. #6
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    This code will work fine:

    Code:
    #include <iostream>			
    
    using namespace std;
    
    int main()
    {
      int age;
      cout << "Please input your age: ";
      cin >> age;
      if( age < 100 )
      {
         cout << "You are pretty young.";
      }
      else if( age == 100 ) 
      {
         cout << "You are old.";
      }
      else
      {
        cout << "You are really old.";
      }
      cin.ignore( 9999, '\n' );
      cin.get();
      return 0;
    }
    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Code:
    include <iostream.h>
    should be
    Code:
    #include <iostream>
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    Administrator webmaster's Avatar
    Join Date
    Aug 2001
    Posts
    967
    In response to WDT: the tutorials on the site are in the process of being updated.

  9. #9
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    Code:
    #include <iostream>
    #include <stblib.h>
    using namespace std;
    			
    int main()				//Most important part of the program!
    {
      int age;				//Need a variable...
      cout<<"Please input your age: ";	//Asks for age
      cin>>age;				//The input is put in age
      if(age<100)				//If the age is less than 100
      {
         cout<<"You are pretty young!";     //Just to show it works
      }
      else if(age==100)		//I use else just to show an example 
      {
         cout<<"You are old";		//Just to show you it works...
      }
      else
      {
        cout<<"You are really old";	//Executed if no other statement is executed
      }
      return 0;
    }
    make sure your creating a console application

  10. #10
    Registered User
    Join Date
    Aug 2003
    Posts
    1,198
    Why include stdlib.h there?? No reason to include that and if you need it I think the standard says its cstdlib

  11. #11
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Also, the return 0; is extraneous.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  12. #12
    Registered User
    Join Date
    Feb 2004
    Posts
    127
    Originally posted by XSquared
    Also, the return 0; is extraneous.
    why extraneous??
    he started with
    Code:
    int main()
    for main function
    it might extraneous if he wrote main function as
    Code:
    void main()

  13. #13
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Originally posted by M_Ghani
    why extraneous??
    he started with
    Code:
    int main()
    for main function
    it might extraneous if he wrote main function as
    Code:
    void main()
    In C++, int main() implicitly returns 0.

    Note: this does not apply to any other function.
    Last edited by Dante Shamest; 03-14-2004 at 03:47 PM.

  14. #14
    Registered User
    Join Date
    Feb 2004
    Posts
    127
    Originally posted by Dante Shamest
    In C++, int main() implicity returns 0.

    Note: this does not apply to any other function.
    really????
    that means that i can write int main() without writing return 0??????

  15. #15
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Yes, technically, you can. The following code is valid:

    Code:
    int main() {}

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Idiot spammer.
    By brewbuck in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-23-2009, 08:19 PM
  2. Feel Like An Idiot
    By golfinguy4 in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 07-04-2003, 12:45 PM
  3. Screaming idiot - shuttle "photo".
    By adrianxw in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 03-08-2003, 07:44 PM
  4. Replies: 0
    Last Post: 02-24-2002, 08:03 PM
  5. Idiot Canadians
    By Troll_King in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-15-2001, 07:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21