HELP!! calculating with time

hi I have to write a program for class in which users will be inputting:
start time = startTime
number of minutes = callDuration

so first off, teacher wants us to input time as a floating point number such as
09.00

how do I validate the time so that users cant input i.e. 09.61 for every hour?
in other words, so the user cant input minutes 60-99 for every hour.

then, when calculating:
endTime = startTime + callDuration

how would I make endTime display a correct time in such a situation:
endTime = 09.45 + 00.30

so that it displays 10.15 not 09.75
I have to write a program for class in which users will be inputting:

why not posting your code and then asking for help?
because I wouldn't even know what to attempt when it came to that part of the program. I cant find any examples or anything online or in my book. ive posted same question on a few forums and cant get a straight answer from anybody.
ive got a problem validating the minutes so that the user can input 00.59 but not 00.60
as the code is right now, the user can input 00.58 but not .59
if I try to tweek the code a little, it will allow 00.59 but will also allow 00.60
can someone help

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
// long-distance call charge.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;



int _tmain(int argc, _TCHAR* argv[])
{   
// variables
	float startTime,        // time at start of call 
		endTime,            // time at end of call
		totalCharge,        // cost of the call
		HH,                 // hours
		MM;                 // minuts

// constants
	const float rpm1 = 0.07,        // rate per minute 1 (00.00 - 07.59)
		rpm2 = 0.12,                // rate per minute 2 (08.00 - 15.59)
		rpm3 = 0.28,                // rate per minute 3 (16.00 - 23.59)
		min_time = 00.00,            // minumum time
		max_time = 23.59,            // maximum time
	    max_min = 0.59;              // maximum minutes

// set the numeric output formatting.
	cout << fixed << showpoint << setprecision(2);

// get user inputs
	cout << "Please enter the start time of the call in HH.MM format using military time. ";
	cin >> startTime;

// validate input
	if (startTime >= min_time && startTime <= max_time)   // validates start time is greater than 00.00 and less than 23.59
		MM = fmod(startTime, 1);                       // extracts minutes from the start time
    else
		// an invalid time was entered.
		cout << "that is an invalid time. Rerun the program and try again. ";
	if (startTime < min_time && startTime > max_time) exit(0);
	if (MM > max_min)
	{
		cout << "that is an invalid time. Rerun the program and try again. ";
		exit(0);
	}
	


	

	return 0;
}

ive got a problem validating the minutes so that the user can input 00.59 but not 00.60

Simply do not use double or float for time. Time is precise value and by the way it is not decimal but you could not tell system that 00.60 = 01.00

So input it as a string (char array) then remove the dot from string and split it to two strings and convert both manually to integers (with atoi or sscanf). Then multiply first value by 60 and add to second if you need.

The following exercise is similar to your problem:
http://codeabbey.com/index/task_view/modulo-and-time-difference
Topic archived. No new replies allowed.