Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not really my cup of tea :-)
13-07-2006, 04:02 PM
Post: #1
Not really my cup of tea :-)
This peice of coding calculates what time an event is in aussie time zone,
relative to US times, took about 30 min to make and debug/test.

All times are in the SI 24 hour military timezone format...cause its a pain having to account for semicolons in scanning in integers
*/

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

void main(void)
{
int mytime, event_time, timezone;

printf("Please make a selection from the following (1, 2 or 3)");
printf("\nTimezone of the event is:");
printf("\n\n1. PST");
printf("\n2. EST");
printf("\n3. CST");
printf("\n\nSelection: ");
fflush(stdin);
scanf("%d",&timezone);

//---begin data validation---------------------------------
while ((timezone != 1)&&(timezone!=2)&&(timezone!=3))
{ clrscr();
printf("The selection you made is invalid. Please chose again.");
printf("\nPlease make a selection from the following (1, 2 or 3)");
printf("\n\n\n\nTimezone of the event is:");
printf("\n\n1. PST");
printf("\n2. EST");
printf("\n3. CST");
printf("\n\nSelection: ");
fflush(stdin);
scanf("%d",&timezone);
}
//---end data validation---------------------------------


switch(timezone)
{ //Pacific Standard Time calculation
case 1:
printf("\nWhat time is the event ? (24hr format xxxx): ");
scanf("%d",&event_time);
mytime = (event_time + 1500); //The "1500" value is how many hours ahead I am from this timezome.
if(mytime <0)
mytime = mytime+2400;
else
if(mytime >2400)
mytime = mytime-2400;
break;


//Eastern Standard Time calculation
case 2:
printf("\nWhat time is the event ? (24hr format xxxx): ");
scanf("%d",&event_time);
mytime = (event_time + 1400); //The "1400" value is how many hours ahead I am from this timezome.
if(mytime <0)
mytime = mytime+2400;
else
if(mytime >2400)
mytime = mytime-2400;
break;


//Central Standard Time calculation
case 3:
printf("\nWhat time is the event ? (24hr format xxxx): ");
scanf("%d",&event_time);
mytime = (event_time + 1600); //The "1600" value is how many hours ahead I am from this timezome.
if(mytime <0)
mytime = mytime+2400;
else
if(mytime >2400)
mytime = mytime-2400;
break;

//wrong entry...restart the program, too lazy to put this in a validating loop, ill do it later
default:
printf("\nlol, not a real time or wrong format...gggzzgzgzgzz,\n restart the program genius");
}


printf("\n\n\nThe time of the raid is %dhrs.\nHoping you can figure out how many days away it is ...",mytime);
printf("\n\nPress any key to end the program.\nRun it again if you want another time figured out.");
getch();
}

[Image: asapmember4fj.gif]
Send this user an email Find all posts by this user
Quote this message in a reply
13-07-2006, 04:12 PM
Post: #2
 
Is there something wrong with this code or is it just here for people to learn from? Also this code is in C rather than C# and in at first glance you could use cstdio and cstdlib instead of stdio.h and stdlib.h also conio.h is not standard and MSVC doesn't even have a copy of it, it also makes your code not portable.

Note: I will try compiling it in a bit to see if you actually want me to fix something.
Send this user an email Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: