Pseudocode problem help! (1 Viewer)

eViLnUt

Cardplayer
Joined
Mar 2, 2005
Messages
179
Location
anywhere ur not lookin
Gender
Male
HSC
2006
"Write an algorithm in pseudocode and flowchart to describe the operation of a digital watch. Remember that it will be in the form of an infinite loop and that a series of counters will be required to count the minutes, seconds and hours. Assume the watch has a 12-hour display and you are to include a procedure (subprogram) for displaying AM and PM."

I have no idea where to start! Can anyone give me help? Thanks.
 

acmilan

I'll stab ya
Joined
May 24, 2004
Messages
3,989
Location
Jumanji
Gender
Male
HSC
N/A
I dont really want to type the algorithm for you as you really wont learn that way, but i can give hints. You will obviously need loops, the main loops should never end, unless of course batteries or power is removed as digital clocks dont ever stop.

Initially youd probably have to have the person set what the time is by inputting the seconds, minutes and hours and whether AM or PM.

Youd need a counter for the seconds, minutes and hour. When the seconds counter reaches 60 it must reset back to 0 and increment the minutes. Similarly when the minutes reaches 60 it must be reset back to 0 and increment the hours.

Everytime the hour reaches 12:00:00 it must switch from AM to PM or PM to AM (depending on what its currently at).

Try doing that for now
 

eViLnUt

Cardplayer
Joined
Mar 2, 2005
Messages
179
Location
anywhere ur not lookin
Gender
Male
HSC
2006
BEGIN MAINPROGRAM
Seconds Display: = 00
Minutes Display: = 00
Hours Display: = 00
AM/PM Display: = AM
User set time by inputting seconds, minutes and hours
User set whether it is AM or PM
Seconds Counter: = 0
Minutes Counter: = 0
Hours Counter: = 0
REPEAT
REPEAT
Seconds Counter = Seconds Counter + 1 after each second
UNTIL Seconds Counter = 60
Reset Seconds Display to 0
REPEAT
REPEAT
Minutes Counter = Minutes Counter + 1 when Seconds Counter = 0
UNTIL Minutes Counter = 60
Reset Minutes Display to 0

This is what I have done so far...I can't link the display and the counters and there are numerous errors in this pseudocode...How do i fix it?

N.B. Indentation doesn't seem to work in posts...
 

PoP 'n' Fresh

Poke me! I giggle!
Joined
Aug 23, 2004
Messages
193
Location
Manly
Gender
Male
HSC
2005
Some quick tips on pseudocode:

All values are 0 by default. Its a waste of time writing all of that.
You dont even need to declare what simple variables you are using.
Never Never have variables with a space in them "Seconds Counter" should be "Seconds_Counter" or "secCounter"... something intrinsic.
Write english prose in situations where you are not sure what exactly has to be done.
eg:
Instead of "Seconds Counter = Seconds Counter + 1 after each second",
write "Increment Seconds_Counter after 1 second"
Also, logically, the loop should finish when it hits 59. 0 - 59 = 60 second counts.

For the linking of display and counter, once again it doesnt really matter how its done. This is pseudocode... its all fake.
so.. something like
Seconds_Display = Seconds_Counter, right after you increment seconds.
Same thing for minutes.

Now for AM/PM, after every hour it should call the subprogram to check.
A simple calculation to check if 12 has been reached is all thats needed.
You can work it out =D
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top