very basic beginner problem

This is a discussion on very basic beginner problem within the C++ Programming forums, part of the General Programming Boards category; when i try to compile my code... i get an error concerning the variable... i was playing aroud with some ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    7

    very basic beginner problem

    when i try to compile my code... i get an error concerning the variable... i was playing aroud with some of the code in lessons 1-3 on the beginners guide... and wondered if you could input x yourself instead of the program declaring the variable itself. the error is on the line
    Code:
     cin>> X;
    should be a simple fix, but i cant figure it out. the line i replaced was
    Code:
      x = 0;
    Code:
     
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      int x;
    
    cin>> X;
    cin.ignore();
      do {
        // "Hello, world!" is printed at least one time
        //  even though the condition is false
        cout<<"Hello, world!\n";
      } while ( x != 0 );
      cin.get();
    }
    hope my tags work... this was my 1st post...

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    C and C++ are case sensitive, that means that x and X are two different things. change X to x and it should compile ok.

    And that do while loop is infinite because the value of x is never changed.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    7
    thank you, yes i planed to include something to change the variable next, but i was compiling there to test to see if i run into the same type problem that i did.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    And you should have a return statement in main().
    Code:
    return 0;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    return statements are automatic in main(). just thought I would say that, and also if you use other function besides main(), then you will have to manually put in return statement. You can use return statement in main() to return a uncsucessfull program. Well anyways thats about it. ASlso another hint which ancient dragon already stated BE VERY CAREFUL with case sensitive. no matter what x is defferent X.

  6. #6
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    I believe return 0 is automatic for C++ in main(), but not for C. Also isn't return 0 required in VC++? Is that wrong?
    Last edited by Dae; 11-25-2005 at 06:18 PM.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by Dae
    Also isn't return 0 required in VC++? Is that wrong?
    yes, vc++ 6.0 is older than the current c++ standards. There are quite a few things that vc++ 6.0 does not support. If you are learning C++ then you should probably not use any of the Microsoft compilers

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Dev-C++ is much better.

    (Ancient Dragon, I sent you a private message . . . .)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner in C facing problem
    By paushali in forum C Programming
    Replies: 3
    Last Post: 10-30-2007, 12:42 PM
  2. Replies: 8
    Last Post: 10-24-2007, 06:46 PM
  3. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  4. a real beginner in Visual C++.net - Q about dialog problem
    By Green Fuze in forum C++ Programming
    Replies: 4
    Last Post: 03-01-2005, 05:21 AM
  5. beginner function problem
    By dellebelle751 in forum C++ Programming
    Replies: 7
    Last Post: 10-30-2002, 07:12 PM

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