question

This is a discussion on question within the C++ Programming forums, part of the General Programming Boards category; Im using the tutorials on this site and im using Dev-C++ and whenever i insert the thing below it will ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    3

    question

    Im using the tutorials on this site and im using Dev-C++ and whenever i insert the thing below it will noit compile and i copied and pasted it from the tutorials

    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;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    > #include <iostream.h>

    Change this to
    #include <iostream>
    using namespace std;

    And be more specific about "will not compile", by including actual error messages
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User deadpoet's Avatar
    Join Date
    Jan 2004
    Posts
    50
    When using source code that may have been written on other operating systems you may have to tweak the includes and namespaces, as well as, your environmental pathing. Generally, compilers do a really good job in telling you what is wrong and you should, just my thoughts, include a little snip from the error that you have questions about. This will aid the other members in trying to answer your question.

    DeadPoet

  4. #4
    Registered User
    Join Date
    Feb 2004
    Posts
    127
    why do u use the brackets after if and else if
    you dont need it since it's only one line (ONLY ONE STATEMENT)

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    It's sort of like tapping your feet when you start to play music/sing, or using your fingers when you start to count. Using braces to delineate the body of all if/else/while statements is easier to learn than the exception of being able skip them if there is just a single line to the body.

    Continue to use them until such time as you find them inconvenient. They aren't wrong, even if they seem unnecessary for a more experienced programmer.

  6. #6
    Registered User deadpoet's Avatar
    Join Date
    Jan 2004
    Posts
    50
    Rock on my brother Elad! It is much easier to read when someone uses correct bracketing. Then I do not have to stop and think about what the author/developer is trying to say. You know, did they mean to have the second or third statement used with the context of the conditional statement.

    Rock On!

    DeadPoet

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

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