CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Join Date
    Oct 2013
    Posts
    9

    Re: If else statement displaying both options.

    Quote Originally Posted by Arjay View Post
    Initialize your variables means to declare them and then set them. You can do this all in one step. In C++, initializing variables prevents a variable from starting out with garbage and it's a good practice to get into (because they are often a source of bugs).

    Code:
    int x;  // uninitialized variable it's anyone's guess what its starting value will be.
    
    int y = 0;  variable declared and initialized to 0
    So if I want the variable to be something the user enters, how do I initialize it?

  2. #17
    Join Date
    Oct 2013
    Posts
    9

    Re: If else statement displaying both options.

    Quote Originally Posted by VictorN View Post
    Begin with reading the Announcement: Before you post....
    Sorry, I despise forums and only did this one to get help from the community because I thought it would be very useful, so I had no idea about things like this.

  3. #18
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: If else statement displaying both options.

    Hi, I am new to coding
    You might like to look at these sites
    http://www.learncpp.com/
    http://www.cplusplus.com/doc/tutorial/

    Going back to your issue re numbers being considered small.

    As suggested earlier, the problem is cin.ignore() which ignores the next character. So if you entered 21, it would be considered as 1 and 67 would be considered as 7 etc.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #19
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: If else statement displaying both options.

    Quote Originally Posted by Sensei Nacho View Post
    Sorry, I despise forums and only did this one to get help from the community because I thought it would be very useful, so I had no idea about things like this.
    Not sure what there is to despise about forums where volunteers help folks solve issues without compensation or in many cases, thanks.

  5. #20
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: If else statement displaying both options.

    Quote Originally Posted by Sensei Nacho View Post
    Before posting, please format your code properly and use code tags. Go advanced, select the code and click '#'.
    How do I do this?
    What don't you understand about the instruction given? Press the 'Go Advanced' button, select the code using normal selection process and then click the '#' button.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured