Thread: Very Basic c++ question

  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
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    >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";

  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
    28,413
    What error did you get?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    Post the smallest and simplest program that demonstrates the error.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    Location
    Inside my computer
    Posts
    24,654
    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.
    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, 09: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, 07:14 AM
  4. Probably a basic question, but...
    By EvilPickles in forum C Programming
    Replies: 5
    Last Post: 09-24-2005, 02:59 PM
  5. basic question
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 02-22-2002, 08:40 PM