### Clock code assignment

I am told to write a program for a clock that has the user input a time with AM or PM and the user will then input an integer value to move the clock forward x amount of minutes. The first example works on my code but the second one does not. Any help on identifying the issue is greatly appreciated!

Example 1
Enter the current time:
11 23 A
How many minutes forward do you want to move the clock?
39
New time: 12:2 PM
Example 2
Enter the current time:
12 34 A
How many minutes forward do you want to move the clock?
9999
New time: 11:13 PM

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465`` ``````#include using namespace std; int main() { int hours, minutes, time; char dayOrNight; cout << "Enter the current time:" << endl; cin >> hours; cin >> minutes; cin >> dayOrNight; cout << "How many minutes forward do you want to move the clock?" << endl; cin >> time; cout << (((hours+((minutes+time)/60))/12)%2) //for debugging purposes, shouldn't return 0 for 12:34A if (hours+((minutes+time)/60)<=12) { if (minutes+time>=60 && hours!=11) { cout << "New time: " << hours+((minutes+time)/60) << ":" << ((minutes+time)%60) << " " << dayOrNight << "M"<< endl; } if (minutes+time>=60 && hours==11 && dayOrNight=='A') { cout << "New time: " << hours+((minutes+time)/60) << ":" << ((minutes+time)%60) << " PM" << endl; } if (minutes+time>=60 && hours==11 && dayOrNight=='P') { cout << "New time: " << hours+((minutes+time)/60) << ":" << ((minutes+time)%60) << " AM" << endl; } if (minutes+time<60) { cout << "New time: " << hours << ":" << minutes+time << " " << dayOrNight << "M" << endl; } } if (hours+((minutes+time)/60)>12) { if ((((hours+((minutes+time)/60))/12)%2)==0) { if (dayOrNight='P') { cout << "New time: " << (hours+((minutes+time)/60))%12 << ":" << ((minutes+time)%60) << dayOrNight << "M" << endl; } if (dayOrNight='A') { cout << "New time: " << (hours+((minutes+time)/60))%12 << ":" << ((minutes+time)%60) << dayOrNight << "M" << endl; } } if (((hours+((minutes+time)/60))/12)%2!=0) { if (dayOrNight='P') { cout << "New time: " << hours+((minutes+time)/60)%12 << ":" << ((minutes+time)%60) << " " << "AM" << endl; } if (dayOrNight='A') { cout << "New time: " << hours+((minutes+time)/60)%12 << ":" << ((minutes+time)%60) << " " << "PM" << endl; } } } }``````

Last edited on
Hello loumarlin1,

Welcome to the forum.

First off:

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

One error I did fine in that you are missing the ";" at the end of line 16.

I will have to run the program to see what it is doing.

Hope that helps for now,

Andy
thanks for looking at this eyesore! I fixed it out of principal on the forum but I've already fixed the actual problem after an hour or so of torture haha.
Topic archived. No new replies allowed.