basically my program lets the user inputs military time( in hour, minute, and seconds). I need to convert this to standard time and have am/pm at the end. Here is what I have so far.
I have a 3 files, time.h, time.cpp (defines functions), and main.cpp (testing). I have a problem in my main function under main.cpp. I don't understand how to set the parameters of the two time objects; t and test. When i do test( hr, min, sec) it shows random numbers when it prints out in standard time.
Can someone help me! Thanks.
(HEADER FILE called Time.h)
#ifndef TIME_H
#define TIME_H
class Time
{
public:
Time(int=0, int=0, int=0);
~Time();
int hour; // valid values are 0 to 23
int minute; // valid values are 0 to 59
int second; // valid values are 0 to 59
void setTime( int, int, int ); // function that checks if inputs are valid
void printUniversal(); // prints in HH:MM:SS format
void printStandard(); // prints in HH:MM:SS AM/PM format
static int count; //counter
};
#include <iostream>
using namespace std;
#include "Time.h"
int main()
{
int hour, minute, second;
Time t(); //t is the time object //(PROBLEM!!!-Dont understand how to write the correct parameters)
Time test(); //test is also a time object //(PROBLEM!!!-Dont understand how to write the correct parameters)
//Time *tp = new Time;
//Time *tarray = new Time[5];
cout << "Enter hour in military time ";
cin >> hour;
cout << "Enter minute ";
cin >> minute;
cout << "Enter second ";
cin >> second;
cout << "\nThe standard time is ";
t.printStandard(); //(PROBLEM!!!- I have the number 12 appearing right after AM and i can't get rid of it. )
cout << "The universal time is ";
test.printUniversal();
cout << endl;
return 0;
} // end main
Last edited by captjack; February 22nd, 2012 at 12:52 AM.
Reason: adding details
I was able to figure out the parameters and get rid of the 12 (due to the unnecessary sizeof(Time)). I made a very silly mistake and was calling the function before inputting variables.
Bookmarks