I am working on a project for my class, and i am trying to put my functions into a library. It isnt working for some reason. here is what i have:
main file for my program:
Code:
/* Name: Shawn Pappas
CSC121-002
Program Title: My Liver for a Clock!
Levels Attempted: 1) Add (Level 1) to display the time in a pretty format with leading 0's using a simple branch
2)Add (Level 2) to display the time in American format (AM-PM, that is) as well as 24-hour format.
3)Add (Level 1) to adjust the time from Greenwich Mean Time to US Central Time.
Program Description: This program takes the number of seconds since Jan. 1st 1970 (GMT) and converts it into the
current time GMT. It also displays the current time in US Central Time. US Central Time is currently
computed as -5 GMT because of Daylight Savings Time. Otherwise the conversion would be -6.
I found the current hours by dividing the amount of seconds since Jan. 1st 1970 by how many seconds
were in an hour,then used % to figure out how many hours were remaining that were not complete days.
I did the same for minutes and seconds.
*/
#include <iostream>
#include <ctime>
#include "timegmt.h"
using namespace std;
int main()
{
short hour_gmt, min, sec;
const short sec_hour = 60*60, sec_min = 60, hour_day = 24;
string colon = ":";
time_t seconds;
seconds = time (NULL);
hour_gmt = (seconds/sec_hour)%hour_day; // Calculates the currnet hours GMT
min = (seconds/sec_min)%sec_min; // Calculates the current minutes GMT
sec = seconds%sec_min; //Calculates the current seconds GMT
cout << endl << "The current time in GMT is " << hour_gmt << colon;
lead_0(min);
cout << min << colon;
lead_0(sec);
cout << sec << ".";
// American Standard Time format AM/PM
cout << " (";
hour_ast(hour_gmt);
lead_0(min);
cout << min << colon;
lead_0(sec);
cout << sec;
am_pm(hour_gmt);
// Convert to Central Time
cout << "The current time CST (Central Standard Time) is ";
cout << conv_cst(hour_gmt) << colon;
lead_0(min);
cout << min << colon;
lead_0(sec);
cout << sec << colon;
// CST American Standard Time format AM/PM
cout << " (";
hour_ast(conv_cst(hour_gmt));
lead_0(min);
cout << min << colon;
lead_0(sec);
cout << sec;
am_pm(conv_cst(hour_gmt));
return 0;
}
timegmt.h:
Code:
#ifndef TIMEGMT_H_INC
#define TIMEGMT_H_INC
void lead_0(short time);
void am_pm(short time);
void hour_ast(short time);
short conv_cst(short time);
#endif
and timegmt.c:
Code:
#include "timegmt.h"
#include <iostram>
using namespace std;
void lead_0(short time)
{
if (time < 10)
{
cout << "0";
}
return;
}
void am_pm(short time)
{
if (time > 12)
{
cout << " PM.)\n";
}
else
{
cout << " AM.)\n";
}
return;
}
void hour_ast(short time)
{
if (time == 0)
{ cout << "12:";
}
if (time > 12)
{
cout << time-12 << ":";
}
if ((time != 0) && (!(time > 12)))
{
cout << time << ":";
}
return;
}
short conv_cst (short time)
{
short cst_conv = -5, hour_cst;
if (time + cst_conv < 1)
{
hour_cst = time+24+cst_conv;
}
else
{
hour_cst = time + cst_conv;
}
return(hour_cst);
}
Could someone please tell me what I am doing wrong?
Also, my instructor looked over my origional program before I tried to put the functions into a library, and wanted me to change my functions from:
Code:
void hour_ast(short time)
{
if (time == 0)
{ cout << "12:";
}
if (time > 12)
{
cout << time-12 << ":";
}
if ((time != 0) && (!(time > 12)))
{
cout << time << ":";
}
return;
to:
Code:
void hour_ast(short time)
{
if (time == 0)
{ cout << "12:";
}
else (time > 12)
{
cout << time-12 << ":";
}
if ((time != 0) && (!(time > 12)))
{
cout << time << ":";
}
return;
The problem is that it errors out when i compile it this way. Was my instructer wrong, or is there something else i should do?