tom.t 0 Newbie Poster

Another good suggestion. Everyone has given me a lot to think about, and a good chance of answering the question (which will of course be different) on the exam.

tom.t 0 Newbie Poster

Thanks for that.

I think the question is trying to get us to think about efficiency rather than correcting an error. At least, that's my guess based on the wording.

tom.t 0 Newbie Poster

Thank you both for your suggestions. I think I was a bit thrown by the abstract nature of the question but what you both say makes sense.

tom.t 0 Newbie Poster

Thanks very much.

Yes, I certainly did mean to validate seconds against 59.

Regarding the integer calculations, I'll have to refresh that section. I can see now that I should have used / not MOD.

tom.t 0 Newbie Poster

I have been asked to find the inefficiency in a piece of pseducode. I've looked at it but can't see it.

IF count > 10 THEN
WHILE x < 0 DO
INPUT x
ENDWHILE
ENDIF

My understanding:
Count is evaluated. If count is <10, the app moves onto the next section. If count is > 10, X is evaluated. Until x is <0, the user will keep being prompted to input x. Once they input x>=0, the loop finishes.

Please note: this is one question on a mock test - it is the whole code. I'm supposed to find the problem with this snippet. eg. there is no mention of x being a value outside of the IF section.

tom.t 0 Newbie Poster

I'm writing pseducode for a Java class. Obviously being pseudo the language shouldn't matter but thought I'd mention it as it would explain any 'bias' I have. BTW, this is my first programming class. I'm revising for my end of semester exam.

Write a pseudo code algorithm which will input a real number. The number represents a length of time, hh.mmss where hh=hours, mm = minutes and ss = seconds. If the input is valid then the algorithm should output the time hours, minutes and seconds.

My attempt:
MAIN
INPUT time
hours = extractHours<-time
minutes=extractMinutes<-time
seconds=extractSeconds<-time
IF (validateTime<-hours, minutes, seconds) THEN
OUTPUT hours, minutes, seconds
END IF

extractHours
hours=(int)time

extractMinutes
tempMinutes=(int)(time*100)
minutes=tempMinutes MOD 100

extractSeconds
tempSeconds=(int)(time*10000)
seconds=tempSeconds MOD 10000

validateTime
isValid=false
IF (0 <= hours <=23) AND (0<= minutes <=59) AND (0<=seconds <=60) THEN
isValid=true
END IF