Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
September 8th, 2011, 02:11 AM
 aruji73
Registered User

Join Date: Sep 2011
Posts: 1
Time spent in forums: 31 m 11 sec
Reputation 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
September 8th, 2011, 05:45 AM
 Makoae
Registered User

Join Date: Sep 2011
Posts: 2
Time spent in forums: 3 h 19 m 45 sec
Reputation 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.

#3
September 8th, 2011, 01:26 PM
 ManiacDan
Sarcky

Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 10,515
Time spent in forums: 2 Months 3 Weeks 5 Days 13 h 26 m 12 sec
Reputation Power: 6300
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

 Viewing: Dev Shed Forums > Other > Beginner Programming > Pseudocode help