dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Beginner Question Regarding Nested If-Else Structure Implementation

  1. #1
    Join Date
    Apr 2011
    Posts
    1

    Beginner Question Regarding Nested If-Else Structure Implementation

    I am taking a Java course at my local CC, and I have managed to write a fairly concise albeit basic program utilizing a scanner object. The code is attached, and if you think it looks kind of repetitive...well it is. We're supposed to demonstrate a number of techniques. My question is a two-parter. First and foremost, where do you think a good implementation of an if-else structure would be? I was thinking of using one to provide parameters for the user inputed int for the ramCount question (if 1-6 else repeat question with additional print statement specifying the accepted int range). Second, is there anyway to restart the program based on a an if-else question at the end of the program? I have googled it quite a bit, and have seen a solutions using do-while, but I would be interested in completing it using if-else.

    Thanks guys, I may be a total noob with code outside of HTML and CSS, but I'm here to learn.
    Attached Files Attached Files

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Beginner Question Regarding Nested If-Else Structure Implementation

    Some contributors here will not follow links to code. Post the relevant code in CODE tags (see my sig).

    First and foremost, where do you think a good implementation of an if-else structure would be?
    if-else is good wherever you need to choose between two options based on some boolean (true/false) value or expression. Some things you need to decide for yourself.

    is there anyway to restart the program based on a an if-else question at the end of the program?
    If you want to give the user the choice of restarting the program or quitting, you'll need to put it in a loop so they can loop back to the start. An if-else alone won't do it. Loop structures have a termination condition, which can stop the loop, so they effectively have an if-else built in (e.g. the 'while' condition in a do-while).

    If you understand what you're doing, you're not learning anything...
    Anon.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)