please help me on this...

I am currently taking a course on C++ and struggling with it so bad. Can anybody help me out with this program? I suppose to calculate a time difference, but my problem is the compiler keeps giving me an error, that i don't know how to fix. Can anybody help, is my program correct? thank you so much!


#include <iostream>
using namespace std;

int do_math(int hour_now, int minute_now, int now_time, int hour_future, int minute_future, int future_time);

bool good_choice(char AP);

int main (){

int hour_now, minute_now, now_time, hour_future, minute_future, future_time, total_minutes;

cout<<"This machine calculates the time difference, enter time in hours, minutes and enter am or pm"<<endl;
cout<<"Enter present time"<<endl;
cin>>hour_now;
cin>>minute_now;
cin>>now_time;
cout<<"Enter the future time"<<endl;
cin>>hour_future;
cin>>minute_future;
cin>>future_time;

total_minutes = do_math(hour_now, minute_now, now_time, hour_future, minute_future, future_time);

cout<<"The time difference is: "<<total_minutes<<endl;

return 0;
}

int do_math(int hour_now, int minute_now, int now_time, int hour_future, int minute_future, int future_time)

{

int const hour_difference = 12, half_hour = 6, minutes = 60;
int sametime_zone, differ_timezone, totalminutes;

while (good_choice){
if ((hour_now == hour_difference) && (hour_future >= half_hour));

sametime_zone = hour_difference - hour_future;

if ((hour_now == hour_difference) && (hour_future <= half_hour));

sametime_zone = hour_future;

if (hour_now != hour_difference);

sametime_zone = (hour_difference - hour_now)+(hour_difference+hour_future);

totalminutes = (sametime_zone/minutes)+(minute_now+minute_future);

else

if ((now_time == 'P' && future_time == 'A') and (hour_future >= half_hour))

differ_timezone = hour_difference+(hour_future - hour_now);

if ((now_time == 'P' && future_time == 'A') and (hour_future <= half_hour))
differ_timezone = hour_difference-(hour_future - hour_now);

totalminutes = (differ_timezone/minutes)+(minute_now+minute_future);

return (totalminutes);

}
bool good_choice(char AP);

if (now_time == 'A' and future_time == 'A')||(now_time == 'P' and future_time == 'P');
return true;
else
return false;
}
What's the error you're getting, and what line of code is it on?
It says the errors are:

time2.cpp: In function int do_math(int, int, int, int, int, int):
time2.cpp:36: warning: the address of bool good_choice(char) will always evaluate as true
time2.cpp:51: error: else without a previous if
time2.cpp:67: error: expected primary-expression before || token
time2.cpp:69: error: else without a previous if (this is the last else before the return false)

I don't see why they are wrong. That's why i am confused...
ya i'm workin hard on this. I did notice the bool was messed up. i think I almost got it (even tho i basically rewrote the whole thing.

just notice that"now_time and future_time" are initiated as integers when there actually an array of characters............ so maybe you should start there.
Last edited on
I'm sorry English is not my first language. What does it mean? Do i messed up the whole thing including the time conversion formula? Or is it just my loops structure and boolean usage are wrong?

The planned to use boolean this way:
if the user input A for AM for the current time and input A for the future time then bool is true (same goes for P for PM for both now time and future time). Else wrong.

That means i have to declare char for the boolean i gues...

I'm sorry for making you working so hard on this... thank you :)
ok well I'm actually gettin ready to go to bed but i'll share with you what I've come up with so far and you can change it play with it ect.

I just got this to run with no errors but my first test it returned a zero....... so there obviously somekinda mistake in here some where. But listen To make this simplier I basically used "am" as default and "pm" as now_time + 12 to use it like military time. just made it easier for me to wrap my mind around. heres my code good luck. Remeber I'm a noob myself so I'm deffinetly not perfect but I changed it alot

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
using namespace std;
int whatsgoinon();
//int do_math(int hour_now, int minute_now, int hour_future, int minute_future, );
char now_time[2];
char future_time[2];
//bool good_choice(char AP);
char cAm, cPm;
int hour_now, minute_now, hour_future, minute_future, total_minutes;
int iNpm = hour_now + 12;
int iFpm = hour_future +12;
int main ()
{

cout<<"This machine calculates the time difference, enter time in hours, minutes and enter am or pm"<<endl;
cout<<"Enter present time"<<endl;
cout<<"Enter hour";
cin>>hour_now;
cout<<"Enter minutes";
cin>>minute_now;
cout<<"Enter am or pm";
cin>>now_time;
cout<<"Enter the future time"<<endl;
cout<<"Enter hour";
cin>>hour_future;
cout<<"Enter minute";
cin>>minute_future;
cout<<"Enter am or pm";
cin>>future_time;

switch(now_time[2])
{	case 'am':
		return 0;
		break;
	case 'Am':
return 0;
	case 'AM' :
		return 0;
		break;
		case 'aM' :
			return 0;
			break;
		case 'pm' :
			 hour_now = iNpm;
			break;
			case 'Pm' :
				 hour_now = iNpm;
				break;
			case 'PM' :
				 hour_now = iNpm;
				break;
			case 'pM' :
 hour_now = iNpm;
break;
}

switch(future_time[2])
{	case 'am':
		return 0;
		break;
	case 'Am':
return 0;
break;
	case 'AM' :
		return 0;
		break;
		case 'aM' :
			return 0;
			break;
		case 'pm' :
			 hour_future = iFpm ;
			break;
			case 'Pm' :
				 hour_future = iFpm;
break;
			case 'PM' :
				 hour_future = iFpm;
				break;
			case 'pM' :
 hour_future = iFpm;
break;
}
//total_minutes = do_math(hour_now, minute_now, now_time, hour_future, minute_future, future_time);

cout<<"The time difference is: "<<total_minutes<<endl;
system("PAUSE");
return 0;
}



int whatsgoinon(int hour_now,int minute_now, int hour_future, int minute_future)
{int totalminutes;

 if(hour_now > hour_future)
	cout<<"Where goin back to the Future";
	totalminutes = ((hour_now - hour_future) * 60) + (minute_now - minute_future);

	return totalminutes;
if(hour_now = hour_future)
	if(minute_now > minute_future)
		totalminutes= minute_now - minute_future;
		return totalminutes;

		if(minute_now < minute_future)
			totalminutes = minute_future-minute_now;
			return totalminutes;

				if(minute_now = minute_future)
					cout<<"you entered the same exact time";
					
						return 0;

if(hour_now < hour_future)
	totalminutes = ((hour_future - hour_now  ) * 60) + (minute_now - minute_future);

	return totalminutes;


}
Thank you so much! I'll see to it. Good night! :)
Topic archived. No new replies allowed.