I am writing a program that gives you 4 options of different cities. When a city is selected, you enter the current time from your location ( which happens to be Newfoundland Time) and it will convert this time into pacific and eastern time depending on the city. The program will continue until q is entered.
My issue is with the 24 hour clock, when 4:30(hours:minutes) is subtracted from say local time 15:00 my program works fine and provides a return of 10:30. However, if the time entered is 2:30, my return will be -2:00, which on a twenty four hour clock should be 22:00. How can i work around this. Here is my code, not top of the line but i am a newbie.
# include <iostream>
# include <string>
using namespace std;
char options;
string time, hrs, mins;
cout << " Choose an option [abcdq]: ";
cin >> options;
while (options != 'q'){
cout << " Enter local time in St. John's (hh:mm): ";
cin >> time;
int len = time.length();
int pos = time.find (":");
hrs = time.substr(0,pos);
mins= time.substr(pos+1, len);
int tHrs = atoi(hrs.c_str());
int tMins = atoi(mins.c_str());
int tTime = (tHrs*60)+ tMins;
int pacific, hPac, mPac, eastern, hEast, mEast;
switch(options){
case 'a':
pacific= tTime-270; // calculates total minutes of day has passed in pacific time
hPac= pacific/60; // turns these minutes into hours
mPac= pacific%60; // turns remainder into minutes
cout << " Local time in Vancouver: " << endl <<"*" << hPac << ":"<< mPac << endl;
break;
case 'b':
pacific= tTime-270;
hPac= (pacific/60);
mPac= pacific%60;
cout << " Local time in San Fransisco: " <<endl<< "*" << hPac << ":"<< mPac << endl;
break;
case 'c':
eastern= tTime-90;
hEast= eastern/60;
mEast= eastern%60;
cout << " Local time in Toronto: " << endl << "*" << hEast << ":" << mEast;
break;
could you elaborate more. how and what step would i add 24 hours, i assume using an if statement? and will this keep the minutes from being negative as well?