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.
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace 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;
}
elseif (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;
}
elseif (weight > 5)
{
total = weight * 2.45;
cout << "The total price to ship this package is $" << std::fixed << std::setprecision(2)
<< total << '\n'<< endl;
}
elseif (weight <= 0)
{
cout << "YOU HAVE ENTERED AN INVALID WEIGHT. GOODBYE ! " << endl;
}
system("pause");
return 0;
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
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
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.