| | |
Pseduocode help - extracting parts of a real number
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 6
Reputation:
Solved Threads: 0
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
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
1
#2 21 Days Ago
At the validation I believe that the seconds should until 59. For the hours you 23, 59. Why not the same for seconds.
For the extract when you multiply and then do a mod, you will get 0.
123 * 100 = 12300
12300 mod 100 = 0
12300/100 = 123
mod returns what is left from the division:
9 = 2 * 4 + 1
9 mod 2 = 1
9 mod 4 = 1
This is the time: 125345 (12:53:45)
In java when you divide an int with an int you will get an int:
125345/100 = 1253
1253 * 100 = 125300
125345/100.0 = 1253.45
So when you divide by 100 you have:
1253
The time is:
125345
1253
Think how can you get the seconds.
THEN:
1253 / 100 =
12
Now how can you get the minutes.
The 12 is the hours
For the extract when you multiply and then do a mod, you will get 0.
123 * 100 = 12300
12300 mod 100 = 0
12300/100 = 123
mod returns what is left from the division:
9 = 2 * 4 + 1
9 mod 2 = 1
9 mod 4 = 1
This is the time: 125345 (12:53:45)
In java when you divide an int with an int you will get an int:
125345/100 = 1253
1253 * 100 = 125300
125345/100.0 = 1253.45
So when you divide by 100 you have:
1253
The time is:
125345
1253
Think how can you get the seconds.
THEN:
1253 / 100 =
12
Now how can you get the minutes.
The 12 is the hours
Last edited by javaAddict; 21 Days Ago at 7:03 am.
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
- I need a program that prompts the user to input a real number and promptly rounds it (C)
- Question about how to design a parts location database (Database Design)
- Complex Number Class (C++)
- problem with guess a number program (C++)
- extracting an arbitrary number of numbers from a string (C)
- How can I modify this program? (C++)
- Extracting Numbers (C)
- Real number to binary? (C)
- How to code a friend template function? (C++)
Other Threads in the Java Forum
- Previous Thread: Input an integer number and display its largest factor
- Next Thread: Casting of int[] to Object[]
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card class client code collision component crashcourse css csv database eclipse ee error fractal free ftp game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linked linux list loan machine map method methods migrate mobile netbeans objects oriented output phone physics printf problem program programming project projects radio recursion replaydirector reporting researchinmotion rotatetext scanner se server service set sms software sort sql string swing test textfield threads tree trolltech ubuntu utility windows






