help with a problem

yes this is a class project but what i want to do is take it a step beyond what was asked for.this is what was asked for

You will need to design an application that will receive the weight of a parcel and calculate and display the cost per kg and the delivery charge for that parcel. Calculate the charges using the following data:

Parcel Weight (kg) Cost per kg ($)
< 2.5 kg $3.50 per kg
2.5 to 5 kg $2.85 per kg
> 5kg $2.45 per kg

Make sure that the weight entered is a positive number, otherwise your program should display an error message and end.

what i want to do is round the total up. if the total was $4.567 i have it set to display $4.56 but i want to know how to round it up to $4.57.

here is my code

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 <iomanip>

using namespace std;

int main()
{
	double weight;
	double cost;
	double total;

	cout << "WELCOME THE THE SHIPPING COST CALCULATOR \n" << endl;

	cout << "Please enter the weight of the package to be shipped in kg. " << endl;
	cin >> weight;

	if (weight > 0 && weight < 2.5)
	{
		total = weight * 3.50;
		cout << "The total price to ship this package is $"  << std::fixed << std::setprecision(2)
         << total << '\n'<< endl;
	}
	else if (weight >= 2.5 && weight <= 5)
	{
		total = weight * 2.85;
		cout << "The total price to ship this package is $"  << std::fixed << std::setprecision(2)
         << total << '\n'<< endl;
	}
	else if (weight > 5)
	{
		total = weight * 2.45;
		cout << "The total price to ship this package is $"  << std::fixed << std::setprecision(2)
         << total << '\n'<< endl;
	}
	else if (weight <= 0)
	{
		cout << "YOU HAVE ENTERED AN INVALID WEIGHT. GOODBYE ! " << endl;
	}

	system("pause");

	return 0;
I'm not sure what you are asking.
if the cost comes to $5.679. i have it showing the cost being $5.67, but in reality a business would round it to $5.68 how can i show the rounded up value if the third floating point is greater than 5
Last edited on
that rounds to the whole number. i want to round the "cents" up
Apply a bit of imagination: If you have $4.567 and you have a function that can round $456.7 to $457, what do you need to do?
Say you have 5.679. Multiply by one hundred to get 567.9. Round that number to the nearest whole number. Now you have 568. Finally, divide that number by 100 to get your answer, 5.68
Thanks shacktar, for depriving the OP's brain of good exercise. :-(
Honestly, the last post I saw was jland68's. I wouldn't have posted my answer had I seen yours.
I see. Well, this forum tends not to hand out the answers to rather simple questions because we don't like people just copying/pasting code and learning nothing. This will make newbies to just forget they should figure things out by themselves and end up being less-than-average programmers.

Have that in mind when helping out beginners in this forum. Cheers.
Topic archived. No new replies allowed.