Like Tree1Likes
  • 1 Post By Elysia

Very Basic c++ question

This is a discussion on Very Basic c++ question within the C++ Programming forums, part of the General Programming Boards category; Hey guys i'm a complete beginner in c++. I'm interested in it from a game dev point of view but ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    3

    Very Basic c++ question

    Hey guys i'm a complete beginner in c++. I'm interested in it from a game dev point of view but am trying to get my head around the basics at the moment.


    Iv been following the tutorials and im just trying my own little statements to see if i can get them to work. I have copied some of the stuff from the tutorial and it worked fine.

    ok, this is one i got to work so far
    Code:
    #include <iostream>
    
    using namespace std;
    
    
    int main()
    
    
    {
        if ( 5<10)
        cout<<"five is less than 10";
    
    
    
    
    
    
    }
    That seem to be fine , working ok.

    Then i tryed to say if 11 was less than 10 say it was false and then go to if 5 was less than 6 say it was true.

    Anyone know how i could say this? I cant really figure out how to, thanks

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,528
    >Then i tryed to say if 11 was less than 10 say it was false and then go to if 5 was less than 6 say it was true
    Code:
    if(11<10)
         cout<<"false";
    else if(5<6)
         cout<<"true";
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    3
    Thanks

    i was trying this but im getting an error

    Code:
    if ( 1 == 2 ) {
    
    cout<<"1 is equal to 2";
    }
    else
    {
    cout<<"1 is not equal to 2";
    }
    What am i doing wrong here?

    I am using code block to try these out, if i was using visual basic are all the rules and syntax still the same?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,303
    What error did you get?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    3
    i got two errors, maybe i have the curleys in the wrong place?

    error: expected initializer before 'if'|error: expected unqualified-id before 'else'|
    ||=== Build finished: 2 errors, 0 warnings ===|

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,303
    Post the smallest and simplest program that demonstrates the error.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    The problem is its not a program - try this:

    (I spent ages in a similar spot just last week)

    Code:
    #include <iostream>
    
    using namespace std;
    
    
    int main(){
    
    if ( 1 == 2 ) {
    cout<<"1 is equal to 2";
    }
    
    else
    {
    cout<<"1 is not equal to 2";
    }
    
    }
    B.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    This works as expected.
    Did you copy and paste whatever was in your editor?

    Also, since you are a beginner, take some time to look into proper indentation.
    dennis.cpp likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-23-2011, 10:00 AM
  2. Very basic C question
    By cnewbie1 in forum C Programming
    Replies: 8
    Last Post: 11-30-2009, 08:53 AM
  3. Basic C++ Question
    By pobri19 in forum C++ Programming
    Replies: 3
    Last Post: 08-23-2008, 08:14 AM
  4. Probably a basic question, but...
    By EvilPickles in forum C Programming
    Replies: 5
    Last Post: 09-24-2005, 03:59 PM
  5. basic question
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 02-22-2002, 08:40 PM

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