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



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>

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.
It makes it easier to read your code and also easier to respond to your post.
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.
Registered users can post here. Sign in or register to post.