|
-
February 3rd, 2012, 03:22 PM
#6
Re: 24-hour Calculator
K so it didint really work out too well... that time thing is 5 hours ahead of my time (its 2:59PM now, it would say its 6:59PM)
Although I did find an alternitive solution to my code, and sorta got it working, theres still 1 problem though when I was debugging it, how would I do my operation backwards for AM?
Like if they enterd PM to start (Because mabey you have a night school or your working a little longer for your shift), this is what happens when the user types PM first (AM first works fine)
School Calculator selected!
When does your school start: 5
AM or PM?
pm
When does your school end: 2
AM or PM?
am
Your school is: 9 hours long.
---------------------------------------
AM to PM is also a little buggy (for example, if you put 5 am - 10pm, it will say its 7 hours (answer is 17)) Any idea how to resolve this issue?
Here is my code:
// Option 4
if (op1 == 4)
{
writeLine ("School Calculator selected!");
writeLine ("");
write ("When does your school start: ");
time1 = readInt ();
writeLine ("");
writeLine ("AM or PM?");
timeframe = readChar ();
//timeframe2 = readChar ();
//if (timeframe=='p'){
//time1+=12;
//}
if(time1>59){
time1++;
}
write ("When does your school end: ");
time2 = readInt ();
writeLine ("AM or PM?");
timeframe2 = readChar ();
//if (timeframe2=='p'){
//time2+=12;
//}
if(timeframe != timeframe2){
if(timeframe == 'a'){
time2=+12;
}
else{
time1+=12;
time2+=24;
}
}
if(timeframe == 'p'){
time2-=time1;
time2-=4;
time2+=time1;
}
answer = time2 - time1;
writeLine ("Your school is: " + answer + " hours long.");
writeLine ("");
writeLine ("Back to menu? (Y|N)");
writeLine ("");
op = readChar ();
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|