Welcome to Po Sled System booting .... Enter current time below: >Enter hour: 2
ID: 3775349 • Letter: W
Question
Welcome to Po Sled
System booting ....
Enter current time below:
>Enter hour: 2
>Enter minutes: 2
>Is it AM or PM?: AM
Current time is 2:02am
Is this time correct (Y or N)? Y
System initializing and TARDIS unit warming....
The Po Sled is engaged and ready for input.
Enter target time below:
>Enter hour: 5
>Enter minutes: 3
>Is it AM or PM?: PM
Target time is 5:03pm
Is this time correct (Y or N)? Y
Security Protocols Engaging
Error: The time difference is greater than 6 hours.
Please re-enter target time.
Enter target time below:
>Enter hour: 1
>Enter minutes: 1
>Is it AM or PM?: AM
Target time is 1:01am
Is this time correct (Y or N)? Y
Security Protocols Engaging
Hold on to your lower posterior regions
Jump was made, current time is 1:01am
You are now in the relative past.
Would you like to jump again (Y or N)? N
System shutting down; enjoy the past.
how do i code this in C++?
Explanation / Answer
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
int main()
{
//Initial message
cout<<" Welcome to Po Sled";
cout<<" System booting ....";
int sHour, sMin, eHour, eMin;
string sAMPM, eAMPM;
char ch = 'y', st;
int hd, c = 0;
//Continue till y is entered
do
{
//Label to reenter the starting time
ST:
cout<<" Enter current time below: ";
cout<<" Enter hour: ";
cin>>sHour;
cout<<" Enter minutes: ";
cin>>sMin;
cout<<" Is it AM or PM?: ";
cin>>sAMPM;
cout<<"Current time is "<<sHour<<":"<<sMin<<sAMPM;
cout<<" Is this time correct (Y or N)? ";
cin>>st;
//If starting time not entered correctly
if(st != 'y')
{
goto ST;
}
else
{
cout<<" System initializing and TARDIS unit warming.... ";
cout<<" The Po Sled is engaged and ready for input. ";
//Label to reenter the ending time
ET:
c++; //Counter for number of times time is entered
cout<<" Enter target time below: ";
cout<<" Enter hour: ";
cin>>eHour;
cout<<" Enter minutes: ";
cin>>eMin;
cout<<" Is it AM or PM?: ";
cin>>eAMPM;
cout<<"Current time is "<<eHour<<":"<<eMin<<eAMPM;
cout<<" Is this time correct (Y or N)? ";
cin>>st;
//If the time entered correctly
if(st == 'y')
{
//If counter is more than one
if(c > 1)
{
c = 0;
cout<<" Hold on to your lower posterior regions ";
cout<<" Jump was made, ";
cout<<"Current time is "<<eHour<<":"<<eMin<<eAMPM;
cout<<" You are now in the relative past. ";
cout<<" Would you like to jump again (Y or N)? ";
cin>>st;
//Check for the jump status
if(st == 'y')
goto ET;
else
{
cout<<" System shutting down; enjoy the past.";
exit(0);
}
}
else
{
//Checks for the time difference
cout<<" Security Protocols Engaging ";
//If starting time is am and ending time is am
if(sAMPM == "am" && eAMPM == "am")
{
hd = eHour - sHour;
cout<<endl<<eHour<<" - "<<sHour<<" = "<<hd;
}
//If starting time is am and ending time is pm
else if(sAMPM == "am" && eAMPM == "pm")
{
hd = (12 - sHour) + eHour;
}
//If starting time is pm and ending time is pm
else if(sAMPM == "pm" && eAMPM == "pm")
{
hd = eHour - sHour;
}
//if starting time is pm and ending time is am
else
{
hd = (12 - sHour) + eHour;
cout<<endl<<eHour<<" - "<<sHour<<" = "<<hd;
}
//If time difference is greater than 6
if(hd > 6)
{
cout<<" Error: The time difference is greater than 6 hours. ";
cout<<" Please re-enter target time. ";
goto ET;
}
//If starting time is less than 6
else
{
cout<<" System Stated. Enjoy Your Time.";
exit(0);
}
}
}
}
}while(ch == 'y' || ch == 'Y');
}
Output:
Welcome to Po Sled
System booting ....
Enter current time below:
Enter hour: 2
Enter minutes: 3
Is it AM or PM?: am
Current time is 2:3am
Is this time correct (Y or N)? y
System initializing and TARDIS unit warming....
The Po Sled is engaged and ready for input.
Enter target time below:
Enter hour: 5
Enter minutes: 6
Is it AM or PM?: pm
Current time is 5:6pm
Is this time correct (Y or N)? y
Security Protocols Engaging
Error: The time difference is greater than 6 hours.
Please re-enter target time.
Enter target time below:
Enter hour: 12
Enter minutes: 2
Is it AM or PM?: am
Current time is 12:2am
Is this time correct (Y or N)? y
Hold on to your lower posterior regions
Jump was made, Current time is 12:2am
You are now in the relative past.
Would you like to jump again (Y or N)? y
Enter target time below:
Enter hour: 5
Enter minutes: 6
Is it AM or PM?: am
Current time is 5:6am
Is this time correct (Y or N)? y
Security Protocols Engaging
5 - 2 = 3
System Stated. Enjoy Your Time.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.