Rounding Minutes up to nearest Hour.

Hi guys. I'm currently taking Beginning Visual Basic programming class.
I'm doing my 3rd project but I am completely stuck and cannot continue.

I am doing a project where I have to program a bill generator and I have to include a rate and time expressed in minutes. I kind of understand rounding at least rounding up to the nearest whole number, but I have to round minutes up to the nearest number.

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
	// 1.0 Input
	cout << "Marlene's Outfit Rental Calculator" << endl << endl;
	cout << "Please enter the following values:\n" << endl;

	// 1.1 MINUTES RENTED
	float rentalMinutes;
	cout << "Total Rental Minutes\t-> ";
	cin >> rentalMinutes;
	//. stuck here
	if((rentalMinutes + 0.5) >= (int(rentalMinutes)+1));
	cout << rentalMinutes << " rounds to " << int(rentalMinutes)+1 << endl;
        // I don't even know what I am doing here.
	cout.setf(ios::showpoint);
	cout.setf(ios::fixed);
	cout.precision(60);
	getch();
}
	


For example, if I was to input 61 I am supposed to round it up to the next hour, 120 minutes. Or, if it was 50 minutes I'm supposed to round it to 60.
I can round 61 to 62, but I can get it to round to 120.

Any help would be greatly appreciated guys.

Oh, and this isn't my entire code, I just posted what I am truly having trouble with, the other stuff I can manage. (kinda :P)
If the modulus of rentalMinutes divided by 60 is greater than zero, then add 60 minutes to the result of the integer division between rentalMinutes and 60.
Hi guys. I'm currently taking Beginning Visual Basic programming class.

It's usually good for a course to know what the course is... this is C++

Every hour is a multiple of 60, so if 60 is not evenly divisible into a number, it needs to be rounded up. Just increment the number to a multiple of 60 by adding hours % number to number/
EDIT: Damn, already posted while I was typing :(
Last edited on
I still don't get it, I'm sorry I'm stupid.

This is how I'm doing it.

	// 1.1 MINUTES RENTED
	float rentalMinutes;
	cout << "Total Rental Minutes\t-> ";
	cin >> rentalMinutes;
	//. stuck here
	if((rentalMinutes / 60) > 0);
	{ 
	rentalMinutes/60 + 60;
	}


Edit: ascii, I'm taking com120
Last edited on
Your if is wrong. Your if reads: "If the integer division between rentalMinutes and 60 is greater than zero". But it has to read: "If the modulus of the integer division between rentalMinutes and 60 is greater than zero".
This is my entire code. It's still work in progress, I tried defining an hour by dividing realMinutes by 60. I got over that one hurdle; It works sofar, but I'm still working on it.

I would have liked to have learned to use modulus, but I just didn't get it.

Disregard all the extra symbols, it's there for cosmetic features.
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
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
	// 1.0 Input
	cout << "Marlene's Cosplay Outfit Rental Calculator!!!" << endl << endl;
	cout << "Please enter the following values:\n" << endl;

	// 1.1 MINUTES RENTED
	float rentalMinutes;
	cout << "Total Rental Minutes\t-> ";
	cin >> rentalMinutes;
	//. stuck here
	int hours = (rentalMinutes + 59)/60;
	
	if ( !cin )
	{
		// reset input for pause
		cin.clear();
		cin.ignore();

		// report and quit
		cout << "Non-numeric input: Program closing" << endl;
		cout << endl << "Press ENTER to finish...";
		cin.ignore(99,'\n');
		return 1;
	}
	cin.ignore(99,'\n');

	// 1.2 RENTAL RATE
	float rentalRate;
	cout << "Hourly Rental Rate\t-> ";
	cin >> rentalRate;
	if ( !cin )
	{
		cin.clear();
		cin.ignore();

		cout << "Non-numeric input: Program terminating" << endl;
		cout << endl << "Press ENTER to finish...";
		cin.ignore(99,'\n');
		return 1;
	}
	cin.ignore(99,'\n');

	// 1.3 RENTAL FEE
	int flatRentalFee;
	cout << "Enter Rental Fee\t-> ";
	cin >> flatRentalFee;
	if ( !cin )
	{
		cin.clear();
		cin.ignore();

		cout << "Non-numeric input: Program terminating" << endl;
		cout << endl << "Press ENTER to finish...";
		cin.ignore(99,'\n');
		return 1;
	}
	cin.ignore(99,'\n');

	// Calculate Rental Costs
	float totalRentalCost = rentalRate * hours;
	float serviceTax = totalRentalCost * 0.04;
	float totalBill = totalRentalCost + flatRentalFee + serviceTax;
	if ( rentalMinutes >= 1 )
	{

	}

	// 3 OUTPUT (EXTRA SPACING AND SYNTAX FOR APPEARANCE)
	cout << "\n==============================================================" << endl;
	cout << "Rental Bill" << endl << endl;

	cout << "Costume Rental Fee: $		" << flatRentalFee << endl;
	cout << "Total Rental Cost:		" << totalRentalCost << endl;
	cout << "Service Tax:\t\t\t" << serviceTax << endl;
	cout << "			    ----------" << endl;
	cout << "Total Bill:\t    $" << endl << endl << endl;

	// 4 FINISH
	cout << "Programmed by Marlene Bentley" << endl;
	cout << "Press ENTER to exit..." << endl;

	getch();
}


Anyway thank you. :)
Edit: more coder-friendly
Last edited on
Please use [code][/code] instead of [quote][/quote]

This int hours = (rentalMinutes + 59)/60; is not the correct rounding. To get the nearest hour write int hours = (rentalMinutes + 30)/60;

Modulus is 'rest of': 16 % 10 = 6 while integer devision is 16 / 10 = 1
To get the nearest hour write int hours = (rentalMinutes + 30)/60;


You're right, this would round 64 minutes down to 60, but I am trying to round up to 120, 2 hours. Sorry, if I wasn't clear. ^^;
Topic archived. No new replies allowed.