Thread: Pseudocode/Flowchart

  1. #1
    Registered User
    Join Date
    Oct 2014
    Posts
    5

    Pseudocode/Flowchart

    Hello there, I need some help in understanding this. Im not that great in C programming and would appreciate some assistance. This is the question :

    Design an algorithm using flowchart or pseudocode to prompt the user for a series of positive integer values. Calculate the average of these values and display the average at the end of the program. Assume that the user types the sentinel value -1 to indicate “end of data entry.”

    Sample input-output:
    Enter a positive integer (-1 to end) : 5
    Enter a positive integer (-1 to end) : 7
    Enter a positive integer (-1 to end) : 6
    Enter a positive integer (-1 to end) : -1

    The average value is: 6



    I searched online and found out this solution however it is only for three numbers.Is there any way of modifying this to include the sum of x numbers / number of x(integers) to find the average? Please help. Thanks.
    Pseudocode/Flowchart-1-png

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yes, by using a loop.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2014
    Posts
    5
    Hi thanks for replying. exactly where do i add the loop ? and how should i type it ? please give me an idea.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by swagmastah22
    exactly where do i add the loop ?
    To the part that corresponds to "prompt the user for a series of positive integer values" and 'Assume that the user types the sentinel value -1 to indicate "end of data entry.'

    Quote Originally Posted by swagmastah22
    and how should i type it ?
    If you're going for the flowchart option, then this is usually done by an arrow that goes back to an earlier point in the flow. If you're going for the pseudocode option, then typically one would make use of keywords like loop, while or for, possibly indicating the body of the loop either by indentation or by some corresponding keyword like end-loop, end-while or end-for. You should read your learning material for examples.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Oct 2014
    Posts
    5
    Hello again. Is this the correct format ? I appreciate your help.
    Pseudocode/Flowchart-flowchart-jpg
    Attached Images Attached Images Pseudocode/Flowchart-flowchart-jpg 
    Last edited by swagmastah22; 10-27-2014 at 07:27 AM. Reason: wrong picture

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Not quite: there should be an arrow that goes back to an earlier point in the flow. You might want to end the condition with a question mark instead of starting it with "while", or maybe you could write "if".

    EDIT:
    Oh, I see that you replaced the image. Well, there's still the problem where you input x, but your loop condition is i > 0.
    Last edited by laserlight; 10-27-2014 at 07:37 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Request for flowchart or pseudocode!!
    By loke1218 in forum C# Programming
    Replies: 4
    Last Post: 02-01-2013, 10:15 PM
  2. Flowchart to Pseudocode Convert
    By mrexp21 in forum C++ Programming
    Replies: 1
    Last Post: 05-25-2012, 01:49 AM
  3. Flowchart help
    By MstrKurt in forum C Programming
    Replies: 8
    Last Post: 01-17-2012, 01:23 AM
  4. Need help with flowchart
    By moey187 in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2011, 04:25 AM
  5. flowchart. Help!!!
    By chema124 in forum C Programming
    Replies: 3
    Last Post: 12-10-2002, 10:00 AM

Tags for this Thread