I have redo the program and come out of this.
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>
using std::setfill;
using std::setw;
class Time {
public:
Time();
void setTime( int, int );
void printsetUp();
void print_A();
void print_B();
private:
int h;
int m;
};
Time::Time()
{
h = m = 0;
}
void Time::setTime( int p, int l )
{
h = ( p >= 0 && p < 24 ) ? p : 0;
m = ( l >= 0 && l < 60 ) ? l : 0;
}
void Time::printsetUp()
{
cout << setfill( '0' ) << setw( 2 ) << h << ":"
<< setw( 2 ) << m;
}
void Time::print_A()
{
cout << ( ( h == 0 || h == 12 ) ? 12 : h % 12 )
<< ":" << setfill( '0' ) << setw( 2 ) << m
<< ( h < 12 ? " AM" : " PM" ) << endl;
}
void Time::print_B()
{
cout << ( ( h == 0 || h == 12 ) ? 12 : h % 12 )
<< ":" << setfill( '0' ) << setw( 2 ) << m
<< ( h < 12 ? " AM" : " PM" ) << endl;
}
int main()
{
Time t;
int h;
int m;
cout << "Current values are:\n";
cout << "City A: ";
t.print_A();
cout << "City B: ";
t.print_B();
cout << "Enter values for City A:\nHour: ";
cin >> h;
cout << "Minute: ";
cin >> m;
t.setTime( h, m );
cout << "City A: ";
t.print_A();
if ( h <= 2 )
h -= 0;
else if ( h > 2 && h < 24 )
h -= 2;
if ( m <= 5 )
m -= 0;
else if ( m > 2 && m < 60 )
m -= 10;
t.setTime( h, m );
cout << "City B: ";
t.print_B();
return 0;
}
can someone help me.
I want the user to key in the time difference (in hrs) between cities A & B like and show the equivalent time of city B.
The user can key in any number in the time difference (in hrs) between cities A & B. ex negative or positive number.
thanks