Help with ceil to round up number

Hello everyone! I am doing an assignment for school and I can not figure out how to use ceil to round up my numbers. I have tried putting it as double ceil = serversNeeded; and putting it in the cout statement and none of them will work. I will attach my code. Any help would be greatly appreciated!

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
  #include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()

{
	int numberOfminutes, numberOfguests;
	string nameOfevent, customerName;


	cout << "Enter the name of the event. " << endl;
	getline(cin, nameOfevent);
	cout << "Enter the customer's first and last name. " << endl;
	getline(cin, customerName);
	cout << "Enter the number of minutes. " << endl;
	cin >> numberOfminutes;
	cout << "Enter the number of guests. " << endl;
	cin >> numberOfguests;

	int hour = 60;
	double serverPay = 18.50;
	double overtime = .50;
	int server = 20;
	double serversNeeded = numberOfguests / server;// how many servers are needed for event
        double roundedUpNumber = ceil(serversNeeded);
	double serverWage = (numberOfminutes - hour) * overtime + serverPay; // cost for one hour
	
	cout << "The number of servers needed is: " << serversNeeded << endl;
	cout << "The cost for servers is: " << serverWage << endl;
	if (numberOfminutes < hour)
	{
		cout << "The customer will be charged for one hour if number of minutes " << endl;
		cout << "is less than 60. " << endl;
	}

		
	

	system("pause");
	return 0;

}
Last edited on
Both numberOfguests and server are integer, so you are getting an integer division.
http://michael-thomas-greer.com/faq/integer-division/
if I put them both as floats would that fix the issue?
Well I fixed the rounding issue but now my formula is incorrect:

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()

{
int numberOfminutes, numberOfguests;
string nameOfevent, customerName;


cout << "Enter the name of the event. " << endl;
getline(cin, nameOfevent);
cout << "Enter the customer's first and last name. " << endl;
getline(cin, customerName);
cout << "Enter the number of minutes. " << endl;
cin >> numberOfminutes;
cout << "Enter the number of guests. " << endl;
cin >> numberOfguests;

int hour = 60;
double overtime = .50;
float server = 20;
float serversNeeded = numberOfguests / server;// how many servers are needed for event
float roundedUpNumber = ceil(serversNeeded);
double serverPay = 18.50 * serversNeeded;
float serverWage = (numberOfminutes - hour) * overtime + serverPay;
double totalServer = serverWage;

cout << "The number of servers needed is: " << roundedUpNumber << endl;
if (numberOfminutes < hour)
{
cout << "The cost of servers for less than one hour is: " << serverPay << endl;
cout << "The customer will be charged for one hour per server if number of minutes " << endl;
cout << "is less than 60. " << endl;
}
else {
cout << "The cost for servers is: " << totalServer << endl;
}
system("pause");
return 0;

}
You have too many types of things in there. Just make everything a double.

Yes, your severWage calculation is wrong. Write it down as an equation on a piece of paper and compare.

Part of the problem is your choice of names is not exact. (Learning to be exact takes some effort.)

For example, you have:

“hour” — but it is really minutes in an hour

“overtime” — this appears to be the amount extra you get paid per hour. Try to think of a more exact name.

“severPay” and “serverWage” — both express the same concept, but one is being used for pay without overtime and one is pay with overtime.

“totalServer” — how is this different from “serverWage”


It helps to write your equations down on a piece of paper first.

server's-pay
  = (rate-per-hour * min( number-of-hours-worked, minimum-hours-before-overtime )
  + (rate-per-hour * overtime-percentage * max( 0, number-of-hours-worked - minimum-hours-before-overtime ))

Does that look right?

Now you can assign values to you numbers:

minimum-hours-before-overtime = 7.5   // for daily calculations
rate-per-hour = 18.50   // presidential rate? nice paycheck for a server!
overtime-percentage = 1.5   // time and a half

(daily/weekly input)
number-of-hours-worked = ?


Now at the end of the day / end of the week, the café manager can calculate how much money he needs to fork over to each employee. For multiple people all working together, you can multiply in the number of people required for the event:

number-of-servers = ?
total-cost-to-pay-servers = server's-pay * number-of-servers


These names may seem ridiculous, and you can certainly cut them down, but... why?

1
2
3
4
5
6
7
double total_cost_to_pay_servers;
double number_of_servers;
double servers_pay;
...
(and so on)
...
double number_of_guests;

Hope this helps.
So we are learning how to use if/else than statements and I thought it would be easier to do server pay without the overtime and server pay with overtime
because the stipulation is that if the time is under 60 minutes the server gets paid for a full 60 minutes of work. That's why I have so many variables. I hate that I have so many but I don't know how to shorten it any.
Topic archived. No new replies allowed.