I've search the web, and solved all the errors that appeared till I got a clean build.
Now any time I run the code I run into this issue.
enter hour of mtime : 19
Mmin: 26
Msec: 05
standard time is 12:00:00 AM
military time is 00:00:00
I can't figure out why this isn't displaying any of my inputs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#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
staticint count; //counter
};
#endif
//(HEADER FILE called Time.h)
//(File that contains definitions - Time.cpp)
#include "stdafx.h"
#include "Time.h" //header file that contains the Time class file
#include <iostream>
#include <iomanip>
#include <ctime>
usingnamespace std;
int Time::count = 10;
Time::Time(int hr, int min, int sec)
{
hour = hr; minute = min; second = sec;
count++;
}
Time::~Time()
{
count--;
}
void Time::setTime(int hr, int min, int sec)
{
hour = (hr >= 00 && hr < 24) ? hr : 00; // checks if hour input is valid
minute = (min >= 00 && min < 60) ? min : 00; // checks if minute input is valid
second = (sec >= 00 && sec < 60) ? sec : 00; // checks if seconds input is valid
}
void Time :: printUniversal()
{
cout << setfill('0') << setw(2) << hour << ":" << setw(2) << minute << ":" << setw(2) << second;
}
void Time::printStandard()
{
cout << ((hour == 00 || hour == 12) ? 12 : hour % 12) << ":" << setfill('0') << setw(2) << minute << ":" << setw(2) << second << (hour < 12 ? " AM" : " PM");
}
//(Where I implement the functions - main.cpp)
//#include "Time.h"
//#include <iostream>
//using namespace std;
int main()
{
int hour, minute, second;
Time t; //t is the time object //(PROBLEM!!!-Dont understand how to write the correct parameters)
//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 << "\nThe universal time is ";
t.printUniversal();
cout << endl;
return 0;
} // end main