If else statement displaying both options. - Page 2
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

Thread: If else statement displaying both options.

  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
    Join Date
    Dec 2012
    Location
    England
    Posts
    1,996

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

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

    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
    Join Date
    Dec 2012
    Location
    England
    Posts
    1,996

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center