September 8th, 2011, 02:11 AM

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 0terminated 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 0terminated sequence of numbers given by the user.
September 8th, 2011, 05:45 AM

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.
September 8th, 2011, 01:26 PM

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.