Source code advice

Hi Guys,

Need help on how to come out a program with the below display. Appreciate for your advice. Thanks in advance. Cheers!

Enter hrs, mins and am/pm country A: 10 30 am
Enter time difference (in hrs) of country A & B: 4
Enter hrs and mins of flight duration: 1 20
The arrival local time in city B is 2:50 pm
Show us what you have so far so we can give you suggestions.
Not able to call for the pm/am as per the above example
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int hour1, minute1;
int hour2, minute2;
int hourdif;
int hourdif1;

int main()
{
cout<<"Enter hrs,mins and am/pm of the time of city A:";
cin>>hour1>>minute1>>timetype;
cout<<"Enter time difference( in hrs) between cities A&B:";
cin>>hour2;

hourdif=hour1+hour2;

if (hourdif > 12)
{
hourdif1 = hourdif - 12 ;

cout<<"The equivalent time of city B is "<<hourdif1<<":"<<minute1<<" "<<timetype<<endl<<endl;
}
else
{
cout<<"The equivalent time of city B is "<<hourdif<<":"<<minute1<<" "<<timetype<<endl<<endl;
}
}
You don't seem to use the time-type. Have you considered using a 24 hour clock rather than a 12 hour one? The calculations are a lot easier.

Are you familar with modulus?
i can't use 24hrs b'coz the qns want us to have the above o/p
Just because you don't display it doesn't mean you can't use it internally. How else are you going to cross day boundaries correctly?
Yeah, you can just - 12 hours from the time before you display it.

Why are you using all those globals? Put them in main, they should be in a scope.
any advice....
I don't particular understand the requirement you say your entering data as in:

Enter hrs, mins and am/pm country A: 10 30 am
Enter time difference (in hrs) of country A & B: 4
Enter hrs and mins of flight duration: 1 20
The arrival local time in city B is 2:50 pm

What of this is output and what is input: What questions do you need to ask the user and what do you want the program to display?

is it just the output of the last line?

eg, all you would need is to add the flight time to the current time and the time difference to current time:

so say you enter 8:30am wiht 4 hour difference in country b, and 1.20 flight time then the output time would be: 8:30 + 4:00 = 12:30 + 1:20 = 1:50pm
or 13:50 army time.

is this correct?

this should just be a simple addition using the time class.

perhaps using gmtime ? http://www.cplusplus.com/reference/clibrary/ctime/gmtime/

http://www.cplusplus.com/reference/clibrary/ctime/time/

i would convert input to seconds and use time to calculate.
thanks bro

well the o/p of "The arrival local time in city B is 3:50 pm"

i'm not able to change the am to pm from my prog.

how can i edit to able it change from am to pm or vice versa
Topic archived. No new replies allowed.