SlideShare a Scribd company logo
1 of 11
Download to read offline
C++ program help! Can't find what's wrong with my program.
The sample output is below and the program I wrote is below that. The program is good but if
you enter in a number of minutes like "120" it doesn't know what to do and crashes. Anything
helps. Thank you.
-In this project, the “current time” should be stored in 24-hour format. Only when the user
actually interacts with the program will the output and input be sometimes in 12-hour format.
Implement a main menu that will allow the user to (1) enter the current time, (2) add a forward
delta to the “current time”, (3) add a backwards delta to the “current time”, (4) display the
current time, (5) toggle the interface mode between 24-hour and 12-hour (should impact both
getTime and printTime). The program should identify invalid input for the main menu. When
entering the current time, only allow hours between 0 and 23 and minutes between 0 and 59.
Accept only ‘a’ and ‘p’ when entering the time in 12-hour mode. When entering time deltas, only
allow positive values or 0 (this is true for both forward and backwards time deltas).
Sample Output: (user input in italics)
1 - Enter a time
2 - Add delta to time
3 - Subtract delta from time
4 - Display current time
5 - Toggle 24-hour mode
6 - Exit
> 1
Enter the time with whitespace separating the hours and minutes: 5 50
1 - Enter a time
2 - Add delta to time
3 - Subtract delta from time
4 - Display current time
5 - Toggle 24-hour mode
6 - Exit
> 4
The current time is 05:50
1 - Enter a time
2 - Add delta to time
3 - Subtract delta from time
4 - Display current time
5 - Toggle 24-hour mode
6 - Exit
> 2
Enter an increment of hours and minutes (separated by a space): 0 120
The new time would be 07:50
1 - Enter a time
2 - Add delta to time
3 - Subtract delta from time
4 - Display current time
5 - Toggle 24-hour mode
6 - Exit
> 2
Enter an increment of hours and minutes (separated by a space): 2 20
The new time would be 08:10
1 - Enter a time
2 - Add delta to time
3 - Subtract delta from time
4 - Display current time
5 - Toggle 24-hour mode
6 - Exit
> 5
12-hour mode turned on
1 - Enter a time
2 - Add delta to time
3 - Subtract delta from time
4 - Display current time
5 - Toggle 24-hour mode
6 - Exit
> 1
Enter the time with whitespace separating the hours, minutes, and either 'a' for am or 'p' for
pm: 0 15 a
1 - Enter a time
2 - Add delta to time
3 - Subtract delta from time
4 - Display current time
5 - Toggle 24-hour mode
6 - Exit
> 4
The current time is 12:15 am
1 - Enter a time
2 - Add delta to time
3 - Subtract delta from time
4 - Display current time
5 - Toggle 24-hour mode
6 - Exit
> 3
Enter a decrement of hours and minutes (separated by a space): 1 15 The new time would be
11:00 pm
1 - Enter a time
2 - Add delta to time
3 - Subtract delta from time
4 - Display current time
5 - Toggle 24-hour mode
6 - Exit
> 3
Enter a decrement of hours and minutes (separated by a space): 0 90 The new time would be
10:45 pm
*****This is the program I wrote:
#include // file processing
#include // cin and cout
#include // toupper
#include // setw
#include // cstring functions strlen, strcmp, strcpy stored in string.h
#include // string class
#include
using namespace std;
void calcDeltaFutr(int h, int m, int deltaH, int deltaM, int& hNew, int& mNew, bool mode);
void calcDeltaPast(int h, int m, int deltaH, int deltaM, int& hNew, int& mNew, bool mode);
void getTime(int &h, int &m, bool mode);
void rollTimeForward(int& h, int& m, bool mode);
void rollTimeBack(int& h, int& m, bool mode);
void printTime(int h, int m, bool mode);
int current_h=-1,current_m=-1;//current time..
bool mode=true;//24 hr format
int main()
{
int choice=-1,c=0;
while(choice!=6)//loop.. exits when user gives 6
{
cout<<" 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display
current time 5 - Toggle 24-hour mode 6 - Exit ";
cout<<"Enter ur choice:";
cin>>choice;//taking user choice
if((choice!=1)&&c==0)
{
cout<<" First Enter current time....  ";//errror message..
}
else if(choice==1)
{
c=1;
getTime(current_h,current_m,mode);//calling function that takes time from the user
//cout<>deltaH;cin>>deltaM;
calcDeltaFutr(current_h,current_m,deltaH,deltaM,hNew,mNew, mode);
current_h = hNew;
current_m = mNew;
cout<<" The New time would be:";
printTime(hNew,mNew,mode);
}
else if(choice==3)
{
int deltaH,deltaM,hNew,mNew;
cout<<"Enter an decrement of hours and minutes (separated by a space):";
cin>>deltaH;cin>>deltaM;
calcDeltaPast(current_h,current_m,deltaH,deltaM,hNew,mNew,mode);
current_h = hNew;
current_m = mNew;
cout<<" The New time would be:";
printTime(hNew,mNew,mode);
}
else if(choice==4)
{
cout<<" The Current time is:";
printTime(current_h,current_m,mode);
}
else if(choice==5)
{
if(mode==false)
mode = true;
else mode = false;
}
else
{
cout<<"  Select appropriate choice...  ";//error message
}
}
return 0;
}
void getTime(int& h,int& m,bool mode)//function that takes current time as input from the user
{
int hh,mm;
while(true)
{
if(mode==true)
{
cout<<" Enter the time with whitespace separating the hours and minutes:";
cin>>hh;
cin>>mm;
if(hh>=24 || mm >= 60|| hh<0 || mm <0)
{
cout<<" Error:invalid time..enter again.. ";
}
else break;
}
else
{
char c;
cout<<"Enter the time with whitespace separating the hours and minutes and (a/p)character:";
cin>>hh;
cin>>mm;
cin>>c;
cin.ignore();
if(hh>=13 || mm >= 60|| hh<0 || mm <0||(c!='a'&&c!='p'))
{
cout<<" Error:invalid time..enter again.. ";
}
else
{
if(c=='p')
{
if(hh!=12)hh=12+hh;
}
else if(hh==12)
hh=0;
break;
}
}
}
h=hh;m=mm;
//cout<=60)
{
hh=hh+mm/60;
mm=mm%60;
cout<24)
{
cout<<"  Error : limit exceeded..Rounding hours.. ";
hh=hh%24;
}
h=hh;m=mm;
}
void printTime(int h, int m, bool mode)
{
if(mode==true)
{
if(h<9)
cout<<'0';
cout<
Solution
#include // file processing
#include // cin and cout
#include // toupper
#include // setw
#include // cstring functions strlen, strcmp, strcpy stored in string.h
#include // string class
#include
using namespace std;
void calcDeltaFutr(int h, int m, int deltaH, int deltaM, int& hNew, int& mNew, bool mode);
void calcDeltaPast(int h, int m, int deltaH, int deltaM, int& hNew, int& mNew, bool mode);
void getTime(int &h, int &m, bool mode);
void rollTimeForward(int& h, int& m, bool mode);
void rollTimeBack(int& h, int& m, bool mode);
void printTime(int h, int m, bool mode);
int current_h=-1,current_m=-1;//current time..
bool mode=true;//24 hr format
int main()
{
int choice=-1,c=0;
while(choice!=6)//loop.. exits when user gives 6
{
cout<<" 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display
current time 5 - Toggle 24-hour mode 6 - Exit ";
cout<<"Enter ur choice:";
cin>>choice;//taking user choice
if((choice!=1)&&c==0)
{
cout<<" First Enter current time....  ";//errror message..
}
else if(choice==1)
{
c=1;
getTime(current_h,current_m,mode);//calling function that takes time from the user
//cout<>deltaH;cin>>deltaM;
calcDeltaFutr(current_h,current_m,deltaH,deltaM,hNew,mNew, mode);
//current_h = hNew; //modified
//current_m = mNew; //modified
cout<<" The New time would be:";
printTime(hNew,mNew,mode);
}
else if(choice==3)
{
int deltaH,deltaM,hNew,mNew;
cout<<"Enter an decrement of hours and minutes (separated by a space):";
cin>>deltaH;cin>>deltaM;
calcDeltaPast(current_h,current_m,deltaH,deltaM,hNew,mNew,mode);
//current_h = hNew;
//current_m = mNew;
cout<<" The New time would be:";
printTime(hNew,mNew,mode);
}
else if(choice==4)
{
cout<<" The Current time is:";
printTime(current_h,current_m,mode);
}
else if(choice==5)
{
if(mode==false)
{
mode = true;
cout<<" 12 hour mode Turned off.. ";
}
else {
mode = false;
cout<<" 12 hour mode Turned on.. ";
}
}
else
{
cout<<"  Select appropriate choice...  ";//error message
}
}
return 0;
}
void getTime(int& h,int& m,bool mode)//function that takes current time as input from the user
{
int hh,mm;
while(true)
{
if(mode==true)
{
cout<<" Enter the time with whitespace separating the hours and minutes:";
cin>>hh;
cin>>mm;
if(hh>=24 || mm >= 60|| hh<0 || mm <0)
{
cout<<" Error:invalid time..enter again.. ";
}
else break;
}
else
{
char c;
cout<<"Enter the time with whitespace separating the hours and minutes and (a/p)character:";
cin>>hh;
cin>>mm;
cin>>c;
cin.ignore();
if(hh>=13 || mm >= 60|| hh<0 || mm <0||(c!='a'&&c!='p'))
{
cout<<" Error:invalid time..enter again.. ";
}
else
{
if(c=='p')
{
if(hh!=12)hh=12+hh;
}
else if(hh==12)
hh=0;
break;
}
}
}
h=hh;m=mm;
//cout<=60)
{
hh=hh+mm/60;
mm=mm%60;
cout<24)
{
cout<<"  Error : limit exceeded..Rounding hours.. ";
hh=hh%24;
}
h=hh;m=mm;
}
void printTime(int h, int m, bool mode)
{
if(mode==true)
{
if(h<9)
cout<<'0';
cout<

More Related Content

Similar to C++ program help! Cant find whats wrong with my program.The sa.pdf

#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
katherncarlyle
 
Here is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdfHere is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdf
doshirajesh75
 
QuecPython_Weather_Station_Demo_Tutorial.pdf
QuecPython_Weather_Station_Demo_Tutorial.pdfQuecPython_Weather_Station_Demo_Tutorial.pdf
QuecPython_Weather_Station_Demo_Tutorial.pdf
JohnEerl
 
Modify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdfModify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdf
aaseletronics2013
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docx
stilliegeorgiana
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docx
denneymargareta
 
#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx
mayank272369
 

Similar to C++ program help! Cant find whats wrong with my program.The sa.pdf (20)

#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
 
Here is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdfHere is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdf
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
 
QuecPython_Weather_Station_Demo_Tutorial.pdf
QuecPython_Weather_Station_Demo_Tutorial.pdfQuecPython_Weather_Station_Demo_Tutorial.pdf
QuecPython_Weather_Station_Demo_Tutorial.pdf
 
C++ project on police station software
C++ project on police station softwareC++ project on police station software
C++ project on police station software
 
Psuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptxPsuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptx
 
C# Loops
C# LoopsC# Loops
C# Loops
 
Modify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdfModify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdf
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
C# Loops
C# LoopsC# Loops
C# Loops
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docx
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docx
 
#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx
 
class12_time.ppt
class12_time.pptclass12_time.ppt
class12_time.ppt
 
First Come First Serve
First Come First ServeFirst Come First Serve
First Come First Serve
 
PROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docxPROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docx
 
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
 
03b loops
03b   loops03b   loops
03b loops
 
DSA 103 Object Oriented Programming :: Week 3
DSA 103 Object Oriented Programming :: Week 3DSA 103 Object Oriented Programming :: Week 3
DSA 103 Object Oriented Programming :: Week 3
 
Operating System Lab Manual
Operating System Lab ManualOperating System Lab Manual
Operating System Lab Manual
 

More from fasttrackscardecors

Missy Crane opened a public relations firm called Goth on August 1, 2.pdf
Missy Crane opened a public relations firm called Goth on August 1, 2.pdfMissy Crane opened a public relations firm called Goth on August 1, 2.pdf
Missy Crane opened a public relations firm called Goth on August 1, 2.pdf
fasttrackscardecors
 
Justify that the following circuit represents the functionality of a .pdf
Justify that the following circuit represents the functionality of a .pdfJustify that the following circuit represents the functionality of a .pdf
Justify that the following circuit represents the functionality of a .pdf
fasttrackscardecors
 
Identify the three major types of controls that organizations can us.pdf
Identify the three major types of controls that organizations can us.pdfIdentify the three major types of controls that organizations can us.pdf
Identify the three major types of controls that organizations can us.pdf
fasttrackscardecors
 
I have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdfI have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdf
fasttrackscardecors
 
I need proper and details explanation for this case study Financial .pdf
I need proper and details explanation for this case study Financial .pdfI need proper and details explanation for this case study Financial .pdf
I need proper and details explanation for this case study Financial .pdf
fasttrackscardecors
 
How is Vietas contribution to mathematics distinctly modern in spi.pdf
How is Vietas contribution to mathematics distinctly modern in spi.pdfHow is Vietas contribution to mathematics distinctly modern in spi.pdf
How is Vietas contribution to mathematics distinctly modern in spi.pdf
fasttrackscardecors
 
Fungal associations with plants Examine a type of fungal association .pdf
Fungal associations with plants Examine a type of fungal association .pdfFungal associations with plants Examine a type of fungal association .pdf
Fungal associations with plants Examine a type of fungal association .pdf
fasttrackscardecors
 
For each problem in this homework, your assignment is to determine .pdf
For each problem in this homework, your assignment is to determine .pdfFor each problem in this homework, your assignment is to determine .pdf
For each problem in this homework, your assignment is to determine .pdf
fasttrackscardecors
 
For each story problem, identofy the opertaion and the interpretatio.pdf
For each story problem, identofy the opertaion and the interpretatio.pdfFor each story problem, identofy the opertaion and the interpretatio.pdf
For each story problem, identofy the opertaion and the interpretatio.pdf
fasttrackscardecors
 
Describe the flow of oxygenated blood from the placenta to the fe.pdf
Describe the flow of oxygenated blood from the placenta to the fe.pdfDescribe the flow of oxygenated blood from the placenta to the fe.pdf
Describe the flow of oxygenated blood from the placenta to the fe.pdf
fasttrackscardecors
 
Consider the following interrupting system. The active-edge inputs o.pdf
Consider the following interrupting system. The active-edge inputs o.pdfConsider the following interrupting system. The active-edge inputs o.pdf
Consider the following interrupting system. The active-edge inputs o.pdf
fasttrackscardecors
 

More from fasttrackscardecors (20)

On a Sunday in April, dog bite victims arrive at Carver Memorial Hos.pdf
On a Sunday in April, dog bite victims arrive at Carver Memorial Hos.pdfOn a Sunday in April, dog bite victims arrive at Carver Memorial Hos.pdf
On a Sunday in April, dog bite victims arrive at Carver Memorial Hos.pdf
 
Molecules like glucose usually need a special transporter protein to.pdf
Molecules like glucose usually need a special transporter protein to.pdfMolecules like glucose usually need a special transporter protein to.pdf
Molecules like glucose usually need a special transporter protein to.pdf
 
Missy Crane opened a public relations firm called Goth on August 1, 2.pdf
Missy Crane opened a public relations firm called Goth on August 1, 2.pdfMissy Crane opened a public relations firm called Goth on August 1, 2.pdf
Missy Crane opened a public relations firm called Goth on August 1, 2.pdf
 
Justify that the following circuit represents the functionality of a .pdf
Justify that the following circuit represents the functionality of a .pdfJustify that the following circuit represents the functionality of a .pdf
Justify that the following circuit represents the functionality of a .pdf
 
Inventor classwhat is the purpose of using assemply constraints.pdf
Inventor classwhat is the purpose of using assemply constraints.pdfInventor classwhat is the purpose of using assemply constraints.pdf
Inventor classwhat is the purpose of using assemply constraints.pdf
 
IncompressibilityI cant understand some parts in a book.The .pdf
IncompressibilityI cant understand some parts in a book.The .pdfIncompressibilityI cant understand some parts in a book.The .pdf
IncompressibilityI cant understand some parts in a book.The .pdf
 
If you were to illuminate an Elodea leaf with light at 550 nm, would.pdf
If you were to illuminate an Elodea leaf with light at 550 nm, would.pdfIf you were to illuminate an Elodea leaf with light at 550 nm, would.pdf
If you were to illuminate an Elodea leaf with light at 550 nm, would.pdf
 
Identify the three major types of controls that organizations can us.pdf
Identify the three major types of controls that organizations can us.pdfIdentify the three major types of controls that organizations can us.pdf
Identify the three major types of controls that organizations can us.pdf
 
I have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdfI have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdf
 
I need proper and details explanation for this case study Financial .pdf
I need proper and details explanation for this case study Financial .pdfI need proper and details explanation for this case study Financial .pdf
I need proper and details explanation for this case study Financial .pdf
 
How is Vietas contribution to mathematics distinctly modern in spi.pdf
How is Vietas contribution to mathematics distinctly modern in spi.pdfHow is Vietas contribution to mathematics distinctly modern in spi.pdf
How is Vietas contribution to mathematics distinctly modern in spi.pdf
 
Fungal associations with plants Examine a type of fungal association .pdf
Fungal associations with plants Examine a type of fungal association .pdfFungal associations with plants Examine a type of fungal association .pdf
Fungal associations with plants Examine a type of fungal association .pdf
 
For each problem in this homework, your assignment is to determine .pdf
For each problem in this homework, your assignment is to determine .pdfFor each problem in this homework, your assignment is to determine .pdf
For each problem in this homework, your assignment is to determine .pdf
 
For each story problem, identofy the opertaion and the interpretatio.pdf
For each story problem, identofy the opertaion and the interpretatio.pdfFor each story problem, identofy the opertaion and the interpretatio.pdf
For each story problem, identofy the opertaion and the interpretatio.pdf
 
Explain a. casting b. overloading c. sentinel d. echoSolution.pdf
Explain a. casting b. overloading c. sentinel d. echoSolution.pdfExplain a. casting b. overloading c. sentinel d. echoSolution.pdf
Explain a. casting b. overloading c. sentinel d. echoSolution.pdf
 
Find all the square roots of the complex number 14i. Write the squar.pdf
Find all the square roots of the complex number 14i. Write the squar.pdfFind all the square roots of the complex number 14i. Write the squar.pdf
Find all the square roots of the complex number 14i. Write the squar.pdf
 
Describe the flow of oxygenated blood from the placenta to the fe.pdf
Describe the flow of oxygenated blood from the placenta to the fe.pdfDescribe the flow of oxygenated blood from the placenta to the fe.pdf
Describe the flow of oxygenated blood from the placenta to the fe.pdf
 
describe two different forms of bindingSolutionTwo forms Co.pdf
describe two different forms of bindingSolutionTwo forms Co.pdfdescribe two different forms of bindingSolutionTwo forms Co.pdf
describe two different forms of bindingSolutionTwo forms Co.pdf
 
Connect onnect mheducation.co.pdf
Connect onnect mheducation.co.pdfConnect onnect mheducation.co.pdf
Connect onnect mheducation.co.pdf
 
Consider the following interrupting system. The active-edge inputs o.pdf
Consider the following interrupting system. The active-edge inputs o.pdfConsider the following interrupting system. The active-edge inputs o.pdf
Consider the following interrupting system. The active-edge inputs o.pdf
 

Recently uploaded

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 

C++ program help! Cant find whats wrong with my program.The sa.pdf

  • 1. C++ program help! Can't find what's wrong with my program. The sample output is below and the program I wrote is below that. The program is good but if you enter in a number of minutes like "120" it doesn't know what to do and crashes. Anything helps. Thank you. -In this project, the “current time” should be stored in 24-hour format. Only when the user actually interacts with the program will the output and input be sometimes in 12-hour format. Implement a main menu that will allow the user to (1) enter the current time, (2) add a forward delta to the “current time”, (3) add a backwards delta to the “current time”, (4) display the current time, (5) toggle the interface mode between 24-hour and 12-hour (should impact both getTime and printTime). The program should identify invalid input for the main menu. When entering the current time, only allow hours between 0 and 23 and minutes between 0 and 59. Accept only ‘a’ and ‘p’ when entering the time in 12-hour mode. When entering time deltas, only allow positive values or 0 (this is true for both forward and backwards time deltas). Sample Output: (user input in italics) 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display current time 5 - Toggle 24-hour mode 6 - Exit > 1 Enter the time with whitespace separating the hours and minutes: 5 50 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display current time 5 - Toggle 24-hour mode 6 - Exit > 4 The current time is 05:50 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display current time 5 - Toggle 24-hour mode
  • 2. 6 - Exit > 2 Enter an increment of hours and minutes (separated by a space): 0 120 The new time would be 07:50 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display current time 5 - Toggle 24-hour mode 6 - Exit > 2 Enter an increment of hours and minutes (separated by a space): 2 20 The new time would be 08:10 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display current time 5 - Toggle 24-hour mode 6 - Exit > 5 12-hour mode turned on 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display current time 5 - Toggle 24-hour mode 6 - Exit > 1 Enter the time with whitespace separating the hours, minutes, and either 'a' for am or 'p' for pm: 0 15 a 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display current time 5 - Toggle 24-hour mode 6 - Exit
  • 3. > 4 The current time is 12:15 am 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display current time 5 - Toggle 24-hour mode 6 - Exit > 3 Enter a decrement of hours and minutes (separated by a space): 1 15 The new time would be 11:00 pm 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display current time 5 - Toggle 24-hour mode 6 - Exit > 3 Enter a decrement of hours and minutes (separated by a space): 0 90 The new time would be 10:45 pm *****This is the program I wrote: #include // file processing #include // cin and cout #include // toupper #include // setw #include // cstring functions strlen, strcmp, strcpy stored in string.h #include // string class #include using namespace std; void calcDeltaFutr(int h, int m, int deltaH, int deltaM, int& hNew, int& mNew, bool mode); void calcDeltaPast(int h, int m, int deltaH, int deltaM, int& hNew, int& mNew, bool mode); void getTime(int &h, int &m, bool mode); void rollTimeForward(int& h, int& m, bool mode); void rollTimeBack(int& h, int& m, bool mode); void printTime(int h, int m, bool mode); int current_h=-1,current_m=-1;//current time..
  • 4. bool mode=true;//24 hr format int main() { int choice=-1,c=0; while(choice!=6)//loop.. exits when user gives 6 { cout<<" 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display current time 5 - Toggle 24-hour mode 6 - Exit "; cout<<"Enter ur choice:"; cin>>choice;//taking user choice if((choice!=1)&&c==0) { cout<<" First Enter current time.... ";//errror message.. } else if(choice==1) { c=1; getTime(current_h,current_m,mode);//calling function that takes time from the user //cout<>deltaH;cin>>deltaM; calcDeltaFutr(current_h,current_m,deltaH,deltaM,hNew,mNew, mode); current_h = hNew; current_m = mNew; cout<<" The New time would be:"; printTime(hNew,mNew,mode); } else if(choice==3) { int deltaH,deltaM,hNew,mNew; cout<<"Enter an decrement of hours and minutes (separated by a space):"; cin>>deltaH;cin>>deltaM; calcDeltaPast(current_h,current_m,deltaH,deltaM,hNew,mNew,mode); current_h = hNew; current_m = mNew; cout<<" The New time would be:"; printTime(hNew,mNew,mode);
  • 5. } else if(choice==4) { cout<<" The Current time is:"; printTime(current_h,current_m,mode); } else if(choice==5) { if(mode==false) mode = true; else mode = false; } else { cout<<" Select appropriate choice... ";//error message } } return 0; } void getTime(int& h,int& m,bool mode)//function that takes current time as input from the user { int hh,mm; while(true) { if(mode==true) { cout<<" Enter the time with whitespace separating the hours and minutes:"; cin>>hh; cin>>mm; if(hh>=24 || mm >= 60|| hh<0 || mm <0) { cout<<" Error:invalid time..enter again.. "; } else break; }
  • 6. else { char c; cout<<"Enter the time with whitespace separating the hours and minutes and (a/p)character:"; cin>>hh; cin>>mm; cin>>c; cin.ignore(); if(hh>=13 || mm >= 60|| hh<0 || mm <0||(c!='a'&&c!='p')) { cout<<" Error:invalid time..enter again.. "; } else { if(c=='p') { if(hh!=12)hh=12+hh; } else if(hh==12) hh=0; break; } } } h=hh;m=mm; //cout<=60) { hh=hh+mm/60; mm=mm%60; cout<24) { cout<<" Error : limit exceeded..Rounding hours.. "; hh=hh%24; }
  • 7. h=hh;m=mm; } void printTime(int h, int m, bool mode) { if(mode==true) { if(h<9) cout<<'0'; cout< Solution #include // file processing #include // cin and cout #include // toupper #include // setw #include // cstring functions strlen, strcmp, strcpy stored in string.h #include // string class #include using namespace std; void calcDeltaFutr(int h, int m, int deltaH, int deltaM, int& hNew, int& mNew, bool mode); void calcDeltaPast(int h, int m, int deltaH, int deltaM, int& hNew, int& mNew, bool mode); void getTime(int &h, int &m, bool mode); void rollTimeForward(int& h, int& m, bool mode); void rollTimeBack(int& h, int& m, bool mode); void printTime(int h, int m, bool mode); int current_h=-1,current_m=-1;//current time.. bool mode=true;//24 hr format int main() { int choice=-1,c=0; while(choice!=6)//loop.. exits when user gives 6 { cout<<" 1 - Enter a time 2 - Add delta to time 3 - Subtract delta from time 4 - Display current time 5 - Toggle 24-hour mode 6 - Exit ";
  • 8. cout<<"Enter ur choice:"; cin>>choice;//taking user choice if((choice!=1)&&c==0) { cout<<" First Enter current time.... ";//errror message.. } else if(choice==1) { c=1; getTime(current_h,current_m,mode);//calling function that takes time from the user //cout<>deltaH;cin>>deltaM; calcDeltaFutr(current_h,current_m,deltaH,deltaM,hNew,mNew, mode); //current_h = hNew; //modified //current_m = mNew; //modified cout<<" The New time would be:"; printTime(hNew,mNew,mode); } else if(choice==3) { int deltaH,deltaM,hNew,mNew; cout<<"Enter an decrement of hours and minutes (separated by a space):"; cin>>deltaH;cin>>deltaM; calcDeltaPast(current_h,current_m,deltaH,deltaM,hNew,mNew,mode); //current_h = hNew; //current_m = mNew; cout<<" The New time would be:"; printTime(hNew,mNew,mode); } else if(choice==4) { cout<<" The Current time is:"; printTime(current_h,current_m,mode); } else if(choice==5) {
  • 9. if(mode==false) { mode = true; cout<<" 12 hour mode Turned off.. "; } else { mode = false; cout<<" 12 hour mode Turned on.. "; } } else { cout<<" Select appropriate choice... ";//error message } } return 0; } void getTime(int& h,int& m,bool mode)//function that takes current time as input from the user { int hh,mm; while(true) { if(mode==true) { cout<<" Enter the time with whitespace separating the hours and minutes:"; cin>>hh; cin>>mm; if(hh>=24 || mm >= 60|| hh<0 || mm <0) { cout<<" Error:invalid time..enter again.. "; } else break; } else {
  • 10. char c; cout<<"Enter the time with whitespace separating the hours and minutes and (a/p)character:"; cin>>hh; cin>>mm; cin>>c; cin.ignore(); if(hh>=13 || mm >= 60|| hh<0 || mm <0||(c!='a'&&c!='p')) { cout<<" Error:invalid time..enter again.. "; } else { if(c=='p') { if(hh!=12)hh=12+hh; } else if(hh==12) hh=0; break; } } } h=hh;m=mm; //cout<=60) { hh=hh+mm/60; mm=mm%60; cout<24) { cout<<" Error : limit exceeded..Rounding hours.. "; hh=hh%24; } h=hh;m=mm; }
  • 11. void printTime(int h, int m, bool mode) { if(mode==true) { if(h<9) cout<<'0'; cout<