trouble with Time concersion between US time zones to UTC then converting to military time

I am attempting to take a meeting start and stop time, add an hour to the beginning and the end(autoScaling), convert those times from a user picked time zone (either et, ct, mt, or pt) to UTC, Then converting those two times to military time. and including a choice for daylight savings time or standard time

** It freezes when I get to the switch case ??????

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;


// Assigning the Variables
int startTime;
int endTime;
char amOrPmStart;
char amOrPmStop;
int timezone;
char seasonal;
double autoScalingStart;
double autoScalingStop;
double meetingLength;



int main ()
{

// Input Daylight Savings Time or Standard Time

cout << "Enter 'd' for Daylight Savings Time or 's' for Standard Time." << endl <<
"Note: In 2020, Daylight Saving Time ends Sunday Nov 1:" << endl;
cin >> seasonal;


// Input Event Start Time and Time Zone

cout << "Enter the time the Townhall Event Starts:" << endl;
cin >> startTime;
cout << endl;



// Validate

while (startTime > 12)
{
cout << "Enter a valid start time:" <<endl;
cin >> startTime;
cout << endl;
}

cout << "Enter 'a' for am or 'p'for pm:" << endl;
cin >> amOrPmStart;
cout << endl;


//Validate

while (amOrPmStart != 'a' && amOrPmStart != 'p')
{
cout << "Enter 'a' or 'p': " << endl;
cin >> amOrPmStart;
cout << endl;
}


// Input Event Stop Time

cout << "Enter the time the Townhall Event Ends:" << endl;
cin >> endTime;
cout << endl;


// Validate

while (endTime > 12)
{
cout << "Enter a valid start time:" <<endl;
cin >> endTime;
cout << endl;
}

cout << "Enter 'a' for am or 'p' for pm:" << endl;
cin >> amOrPmStop;
cout << endl;


//Validate

while (amOrPmStop != 'a' && amOrPmStop != 'p')
{
cout << "Enter 'a' or 'p': " << endl;
cin >> amOrPmStop;
cout << endl;
}


// Input Meeting Length

cout << "Enter the the length of the meeting in hours:" << endl;
cin >> meetingLength;
cout << endl;

// Verrifying Meeting Length Information

while (meetingLength > 6 || meetingLength < 1)
{
cout << "Enter valid meeting Length in hours:" << endl;
cin >> meetingLength;
} cout << endl;


// Verifying Information Input

cout << "Please double check that the information is correct:" << endl <<
"Event Start Time: " << startTime << " " << amOrPmStart << endl <<
"Event End Time: " << endTime << " " << amOrPmStop << endl <<
"Event Length:" << meetingLength << " hours" << endl << endl;


// Input Timezone

cout << "Enter the Event timezone using '1' for eastern, '2' for central, '3' for mountain or '4' for pacific:" << endl;
cin >> timezone;
cout << endl;


//Validate

while (timezone != 1 && timezone != 2 && timezone != 3 && timezone != 4)
{
cout << "Enter a valid timezone either '1', '2', '3', or '4': " << endl;
cin >> timezone;
cout << endl;
}

/////////////////////////////////////////////////////
// Calculating the Autoscaling start and stop time//
///////////////////////////////////////////////////

switch(timezone){
case 1:
if (startTime == 12)
{
if (amOrPmStart == 'p')
{
startTime = (startTime - 12);
}
else if (amOrPmStart == 'a')
{
startTime = (startTime + 12);
}
}
autoScalingStart = startTime + 3;
if (amOrPmStart == 'p')
{
autoScalingStart = (autoScalingStart + 12);
}
while (seasonal == 's')
{
autoScalingStart = (autoScalingStart + 1);
}
cout << "The autoscaling start time is " ;
cout << autoScalingStart << ":00" << endl;
autoScalingStop = (autoScalingStart + meetingLength + 2);
cout << "The autoscaling stop time is ";
cout << autoScalingStop << ":00" << endl;
break;


case 2:
if (startTime == 12)
{
if (amOrPmStart == 'p')
{
startTime = (startTime - 12);
}
else if (amOrPmStart == 'a')
{
startTime = (startTime + 12);
}
}
autoScalingStart = startTime + 4;
if (amOrPmStart == 'p')
{
autoScalingStart = (autoScalingStart + 12);
}
while (seasonal == 's')
{
autoScalingStart = (autoScalingStart + 1);
}
cout << "The autoscaling start time is ";
cout << autoScalingStart << ":00" << endl;
autoScalingStop = (autoScalingStart + meetingLength + 2);
cout << "The autoscaling stop time is ";
cout << autoScalingStop << ":00" << endl;
break;

case 3:
if (startTime == 12)
{
if (amOrPmStart == 'p')
{
startTime = (startTime - 12);
}
else if (amOrPmStart == 'a')
{
startTime = (startTime + 12);
}
}
autoScalingStart = startTime + 5;
if (amOrPmStart == 'p')
{
autoScalingStart = (autoScalingStart + 12);
}
while (seasonal == 's')
{
autoScalingStart = (autoScalingStart + 1);
}
cout << "The autoscaling start time is ";
cout << autoScalingStart << ":00" << endl;
autoScalingStop = (autoScalingStart + meetingLength + 2);
cout << "The autoscaling stop time is ";
cout << autoScalingStop << ":00" << endl;
break;

case 4:
if (startTime == 12)
{
if (amOrPmStart == 'p')
{
startTime = (startTime - 12);
}
else if (amOrPmStart == 'a')
{
startTime = (startTime + 12);
}
}
autoScalingStart = startTime + 6;
if (amOrPmStart == 'p')
{
autoScalingStart = (autoScalingStart + 12);
}
while (seasonal == 's')
{
autoScalingStart = (autoScalingStart + 1);
}
cout << "The autoscaling start time is ";
cout << autoScalingStart << ":00" << endl;
autoScalingStop = (autoScalingStart + meetingLength + 2);
cout << "The autoscaling stop time is ";
cout << autoScalingStop << ":00" << endl;
break;

default:
cout << "enter 1,2,3,4";


}

return 0;
1
2
3
4
while (seasonal == 's')
{
    autoScalingStart = (autoScalingStart + 1);
}
This is an infinite loop.
Last edited on
Topic archived. No new replies allowed.