I posted a simliar issue ealier, but I've changed my approach since then.

``````#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
};

#endif

//(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>

using namespace 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
``````

The issue I'm having is, no matter what I input the same output is display

Standard Time 12:00:00 PM

Universal 00:00:00

I have no clue on how to reslove this issue since I'm not getting any errors messages.

Well, in main(), you never set the value of t. You declare it, so it has the default Time value (midnight of whenever). You need to set t's hour, minute, and second values from the input values.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.