Thread: If Statements Tutorial Code Won't Compile.

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    18

    If Statements Tutorial Code Won't Compile.

    Hi Folks,
    I'm working through cprogramming.com's If Statement's tutorial and created the following script as directed by the tutorial:
    Code:
    #include <iostream.h>
    int main()
    {
    int age; // Variable.
    cout<<"Please input your age: ";
    cin>>age;
    If (age<100)
        {
            cout<<"You are pretty young!";
        }
    Else If(age==100)
        {
            cout<<"You are old";
        }
    Else
        {
        }
    return 0;
    }
    I receive the following errors:
    Compiler: Default compiler
    Executing g++.exe...
    g++.exe "C:\Documents and Settings\David Mackey\My Documents\cprograms\ageasker.cpp" -o "C:\Documents and Settings\David Mackey\My Documents\cprograms\ageasker.exe" -I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32" -I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
    In file included from C:/Dev-Cpp/include/c++/backward/iostream.h:31,
    from C:/Documents and Settings/David Mackey/My Documents/cprograms/ageasker.cpp:1:
    C:/Dev-Cpp/include/c++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
    C:/Documents and Settings/David Mackey/My Documents/cprograms/ageasker.cpp: In
    function `int main()':
    C:/Documents and Settings/David Mackey/My Documents/cprograms/ageasker.cpp:7: `
    If' undeclared (first use this function)
    C:/Documents and Settings/David Mackey/My Documents/cprograms/ageasker.cpp:7: (Each

    undeclared identifier is reported only once for each function it appears
    in.)
    C:/Documents and Settings/David Mackey/My Documents/cprograms/ageasker.cpp:8: parse
    error before `{' token
    C:/Documents and Settings/David Mackey/My Documents/cprograms/ageasker.cpp: At
    global scope:
    C:/Documents and Settings/David Mackey/My Documents/cprograms/ageasker.cpp:9: `
    age' was not declared in this scope
    C:/Documents and Settings/David Mackey/My Documents/cprograms/ageasker.cpp:10: parse
    error before `{' token
    C:/Documents and Settings/David Mackey/My Documents/cprograms/ageasker.cpp:12: syntax
    error before `{' token

    Execution terminated
    If someone could help me through this I would be grateful. I am using Blood's Dev-C++ IDE with MinGW's port of the GNU compiler.
    Respectfully,
    David Mackey.
    - http://www.civilwarsearch.com/ - Civil War Search Directory.
    - http://www.dhq.nu/hutsell/ - Four Free Computer Wargames.
    - http://www.debaunart.com/ - Original and Print Watercolor Artwork.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Else and If should be else and if.
    C and C++ unlike Pascal is case sensitive.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    18
    Thantos,
    Thanks very much for your help. I changed that small bit of code and it worked. :-) May I ask, is there a reason why the designers of C/C++ decided to implement case sensitivity? I imagine there must be some?
    Respectfully,
    David.
    - http://www.civilwarsearch.com/ - Civil War Search Directory.
    - http://www.dhq.nu/hutsell/ - Four Free Computer Wargames.
    - http://www.debaunart.com/ - Original and Print Watercolor Artwork.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes
    Replace the line:

    #include <iostream.h>

    with these lines:

    #include <iostream>
    using namespace std;

    and that should take care of that error. Don't worry about why at this point. Just use those lines at the beginning of every program for now.

    For the other errors, whether or not you capitalize something in C++ is not a random decision for you to make. if-statements are not capitalized, nor are else if-statements or else statements.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    May I ask, is there a reason why the designers of C/C++ decided to implement case sensitivity?
    Efficiency.

  6. #6
    Registered User
    Join Date
    Dec 2003
    Posts
    18
    7stud,
    Thanks for the advice. Any desire to elaborate on what you meant by "efficiency?"
    Respectfully,
    David.
    - http://www.civilwarsearch.com/ - Civil War Search Directory.
    - http://www.dhq.nu/hutsell/ - Four Free Computer Wargames.
    - http://www.debaunart.com/ - Original and Print Watercolor Artwork.

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    It takes less effort to make sure "abcd" is the same as "abcd" then it does to check all the variations such as "AbCd" or "ABCd" etc.

    Also having it case sensitive allows you to have four variables called hi (hi, HI, hI, Hi) though this is definately not recommended.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile time of C versus C++ code
    By circuitbreaker in forum C++ Programming
    Replies: 20
    Last Post: 02-06-2008, 06:26 PM
  2. why the code can compile -- about function pointer
    By George2 in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2008, 03:25 AM
  3. prime numbers code compile error
    By Tony654321 in forum C Programming
    Replies: 5
    Last Post: 10-10-2004, 10:13 AM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. How do they compile code for an OS ?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 49
    Last Post: 03-28-2002, 12:16 AM