I am taking a Computer Science Class, where we are learning C++. The assignment I am working on is here: http://home.earthlink.net/~craie/121...ay.simple.html
The problem I am having is that the output of my program is not working correctly at my conversion to CST and after. Can someone please look at my code and explain why, or give me a good enough example/hint as of why.
Code:
/* Computer Science 1
Name: edit
Email: edit
*/
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
short hour_gmt, hour_cst, min, sec;
const short sec_hour = 3600, sec_min = 60, cst_conv = -5;
time_t seconds;
seconds = time (NULL);
hour_gmt = (seconds/sec_hour)%24;
min = (seconds/sec_min)%60;
sec = seconds%60;
cout << endl;
cout << "The current time in GMT is " << hour_gmt << ":";
if (min < 10)
cout << "0" << min << ":";
else
cout << min << ":";
if (sec < 10)
cout << "0" << sec << ".";
else
cout << sec << ".";
// American Standard Time format AM/PM
cout << " (";
if (hour_gmt > 12)
cout << hour_gmt - 12 << ":";
if (hour_gmt < 1)
cout << "12:";
else
cout << hour_gmt << ":";
if (min < 10)
cout << "0" << min << ":";
else
cout << min << ":";
if (sec < 10)
cout << "0" << sec;
else
cout << sec;
if (hour_gmt > 12)
cout << " PM.)";
if (hour_gmt = 0)
cout << "AM.)";
else
cout << " AM.)\n";
// Convert to Central Time
cout << "The current time CST (Central Standard Time) is ";
if (hour_gmt + cst_conv < 1)
hour_cst = hour_gmt+24+cst_conv;
else
hour_cst = hour_gmt + cst_conv;
cout << hour_cst << ":";
if (min < 10)
cout << "0" << min << ":";
else
cout << min << ":";
if (sec < 10)
cout << "0" << sec << ".";
else
cout << sec << ".";
// CST American Standard Time format AM/PM
cout << " (";
if (hour_cst > 12)
cout << hour_gmt-12 << ":";
if (hour_cst < 1)
cout << "12:";
else
cout << hour_cst << ":";
if (min < 10)
cout << "0" << min << ":";
else
cout << min << ":";
if (sec < 10)
cout << "0" << sec;
else
cout << sec;
if (hour_gmt > 12)
cout << " PM.)";
if (hour_gmt = 0)
cout << "AM.)";
else
cout << " AM.)";
return 0;
}