Can you help me?

A baggage counter charges
$o.50 mimimum fee to deppsit a bag for up to 3 hours and an additional $0.25 for each hour or part thereof over 3 hours.

Assume that no bags are deposited for longer than 6 hours time. Write a program that will calculate and print the baggage counter charges for each of the 5 costumers. Who deposited their bags at this counter.

You should enter the hours deposited for each costumer. Your program should print the consults in a tabular format, and should calculate and print the total of all receipts for a day.

The program should use function. Calculate charges to determine the charhe for each costumer. Output should be in this format:

Costumers hours charges
1 1 0.50
2 1.8 0.50
3 2.0 0.50
4 4.0 0.75
5 6.0 1.25
TOTAL 14.0 3.50

I HOPE YOU CAN HELP ME

Dani AI

Generated

— implement a small helper function that returns the charge for a single deposit and call it for each customer. is right that this is simple arithmetic; the only nontrivial part is "each hour or part thereof," which is handled cleanly with a ceiling operation. Validate inputs (hours between 0 and 6), sum hours and charges, and format the table with fixed decimal places.

Algorithm summary:

  • If hours <= 3.0 → charge = 0.50.
  • Else extra = ceil(hours − 3.0); charge = 0.50 + 0.25 * extra.
  • Keep totals for hours and charges and print with consistent column widths and precision.

Code example (reads 5 customer times, validates input, prints table and totals):

#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <limits>

double calculateCharge(double hours) {
    const double base = 0.50;
    if (hours <= 3.0) return base;
    double extra = std::ceil(hours - 3.0); // hour or part thereof
    return base + 0.25 * extra;
}

int main() {
    std::vector<double> hrs(5);
    std::cout << "Enter hours for 5 customers (0.0 - 6.0):\n";
    for (int i = 0; i < 5; ++i) {
        double h;
        while (!(std::cin >> h) || h < 0.0 || h > 6.0) {
            std::cin.clear();
            std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
            std::cout << "Invalid entry. Enter hours between 0 and 6: ";
        }
        hrs[i] = h;
    }

    double totalH = 0.0, totalC = 0.0;
    std::cout << std::fixed;
    std::cout << std::setw(10) << "Customer" << std::setw(10) << "Hours" << std::setw(12) << "Charges\n";
    for (int i = 0; i < 5; ++i) {
        double c = calculateCharge(hrs[i]);
        totalH += hrs[i];
        totalC += c;
        std::cout << std::setw(10) << (i + 1)
                  << std::setw(10) << std::setprecision(1) << hrs[i]
                  << std::setw(12) << std::setprecision(2) << c << '\n';
    }
    std::cout << std::setw(10) << "TOTAL"
              << std::setw(10) << std::setprecision(1) << totalH
              << std::setw(12) << std::setprecision(2) << totalC << '\n';
    return 0;
}

Note: std::ceil makes the "part of an hour" rule explicit and robust; if avoiding <cmath> is desired, replicate the ceiling logic carefully to avoid floating-point edge cases.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.