views:

74

answers:

1

Hello. I need help with some code that i am writing for a small text rpg. Its basically a clock that simulates a day, which will be 24 minutes instead of 24 hours. 1 second will equal one minute, and 1 minute will equal one hour. The clock will start from 12:00 and go to 12:00. I need ideas on how to write this code. This is code that i have come

time_t rawtime;
 int hours;
 int minutes;
 int seconds;

 struct tm * timeinfo;

 time ( &rawtime );
 timeinfo = localtime ( &rawtime );

 if(timeinfo->tm_hour > 12)
  timeinfo->tm_hour = timeinfo->tm_hour - 12;

 hours = timeinfo->tm_hour;
 minutes = timeinfo->tm_min;
 seconds = timeinfo->tm_sec;
+2  A: 

Just get the current time, convert to seconds, then multiply by sixty. Finally, convert back.

Example:

myrealtime_s = hours*60*60+minutes*60+seconds;
myfaketime_s = myrealtime_s*60;

myfaketime_seconds = myfaketime_s % 60;
myfaketime_minutes = (myfaketime_s/60) % 60;
myfaketime_hours = (myfaketime_s/(60*60)) % 24;

myfaketime_extraseconds = myfaketime_s-(myfaketime_hours*60*60+myfaketime_minutes*60+myfaketime_seconds);
Borealid