Thread: Pseudocode help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Pseudocode help


    Can someone help me write the following in pseudocode for my computer science ?? I am new to programming and this would help me a lot
    The expected behavior of the program is as follows.

    1.The program informs the user that it will compute the sum of a 0-terminated sequence of numbers.
    2.The program prompts the user for each number.
    3.The user inputs each number, one at a time.
    4.Each number given by the user is added to a running total.
    5.When the user gives 0 as input, the program finishes by displaying "The sum is " followed by the sum of all numbers entered by the user.
    Write an algorithm to compute the sum of a 0-terminated sequence of numbers given by the user.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0
    I believe this algorithm can be written in this way;

    1.Declare the number n //which is the input from the keyboard.
    2.Declare the sum and initialise it to zero.
    3.Compute the sum
    do
    begin
    input number n.
    increment sum with n
    endwhile number n is equals to zero
    end
    4.Display the sum.
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    True pseudocode is closer to:
    Code:
    print "Enter numbers when prompted. Entering a zero will cause the SUM of all numbers to be displayed."
    sum = 0;
    while (get_entry() != 0 ) {
      sum += entry();
    }
    print "The sum is ", sum;
    exit;
    If you weren't able to do this yourself, you need to ask your professor or TA for help. This is a very basic example of program flow, not grasping it means you'll be lost for the rest of the semester.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo