user input and program design

This is a discussion on user input and program design within the C++ Programming forums, part of the General Programming Boards category; Hey everyone, I was writing some pseudocode to a very basic program and I was just wondering about something in ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    153

    user input and program design

    Hey everyone,
    I was writing some pseudocode to a very basic program and I was just wondering about something in my design, this is all in pseudocode (obviously ):


    Code:
    int main()
    {
            Prompt for amt_requested
            Get amt_requested
            IF (amt_requested != 0)  AND  ( amt_requested <= 1000)
                     Prompt for interest_rate, loan_duration
                     Get interest_rate, loan_duration
            ENDIF
    
           WHILE (amt_requested != 0 )  AND (amt_requested <= 1000)
                      loop body
           ENDWHILE
    }
    What I was trying to accomplish is I want to run the loop until a sentinel (is that the right word?) value is entered (in this case 0 or anything over 1000), and I wanted to make sure that if a user enters a 0, they dont have to trudge through entering 2 more values for the other variables if they will never be used, so I wrote an if statement that does an initial check on the first value entered,now I was wondering if this is sloppy, or cumbersome, or redundant, anything like that. Thanks yet again for the help! -Chap

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by Chaplin27
    Hey everyone,


    What I was trying to accomplish is I want to run the loop until a sentinel (is that the right word?) value is entered (in this case 0 or anything over 1000)
    There's a bit redundancy, and maybe some logic problems, like what happens if they enter a negative number?


    Code:
    int main()
    {
            Prompt for amt_requested
            Get amt_requested
    
            WHILE (amt_requested > 0 )  AND (amt_requested <= 1000)
            {
                     Prompt for interest_rate, loan_duration
                     Get interest_rate, loan_duration
                     ... process amt or store it for later processing
                     Prompt for amt_requested 
                     Get amt_requested //new amount or sentinel to end
             }   // ENDWHILE
    }
    Last edited by Darryl; 06-09-2005 at 09:51 AM.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    153
    wow darryl, thanks a lot, I'm an idiot! I didnt even think of receiving the other data in the loop body! That changes the whole game, haha. Thanks a lot for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 04:25 PM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  3. Replies: 4
    Last Post: 04-03-2008, 10:07 PM
  4. large program code ,please help
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 01-30-2006, 06:16 AM

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