Hi.. Can anyone please help me to write the following program:

Write a program that will calculate the price to be paid for the development of photographs. The program must use
two overloaded functions, each named calcTotal. If the client wants jumbo photographs, and the film is a 36
exposure film, the client gets 5% discount. If the client wants normal size photographs, and the film is a 36 exposure
film, he may discard up to 6 photographs without having to pay for it. The first function must calculate the total to be
paid for jumbo photographs, and will have one parameter of type int representing the exposure. The second
function will have two parameters of type int representing the exposure and the number of photographs to be
discarded. The functions must decide whether a discount (in the case of the jumbo photographs) or discarding of
photographs (in the case of normal size photographs) is allowed when calculating the total price. The user must
specify whether he wants jumbo size or normal size and the main program must then ask for the number of
photographs to be discarded if applicable. Both functions must return the total to be paid by the client in a variable of
type double. The main function should the display the total price. Define const variables where applicable inside
the function for the price of each photo – R3.40 for a jumbo and R3.20 for a normal size photo, as well as a const
variable for the discount value.
Hoping to be able to solve it by ur help..thank you in advance

Dani AI

Generated

Quick, focused notes that address the actual problems in the posted code and give a clean, working layout.

The main issues seen in ’s submission (and hinted at by ) are:

  • Missing braces around the else block so some input happens unconditionally.
  • Wrong discard logic: the code subtracts the free-photos constant from the discarded count instead of reducing the payable photos by the allowed free amount.
  • Discount is applied unconditionally instead of being gated by the 36-exposure condition.
  • No input validation or case-insensitive handling of the size choice.
  • No formatting for currency output.

A concise, correct approach:

  • Keep two overloaded functions calcTotal(int exposure) and calcTotal(int exposure, int number_discarded).
  • In the normal-size function compute payable = exposure - min(number_discarded, FREE_ALLOWED) and clamp payable to >= 0.
  • In the jumbo function apply the discount only when exposure == 36.
  • Always use braces for multi-statement if/else, use std::toupper for character checks, and print with std::fixed + std::setprecision(2).

Example implementation (compile-tested):

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cctype>

double calcTotal(int exposure) {
    const double PRICE = 3.40;
    const double DISCOUNT = 0.05;
    double total = exposure * PRICE;
    if (exposure == 36) total *= (1.0 - DISCOUNT);
    return total;
}

double calcTotal(int exposure, int number_discarded) {
    const double PRICE = 3.20;
    const int FREE_PHOTO = 6;
    int freeAllowed = std::min(number_discarded, FREE_PHOTO);
    if (freeAllowed < 0) freeAllowed = 0;
    int payable = exposure - freeAllowed;
    if (payable < 0) payable = 0;
    return payable * PRICE;
}

Notes and cautions:

  • Validate numeric input (non-negative exposure and discard numbers) before calling the functions.
  • Use std::toupper(static_cast<unsigned char>(ch)) to avoid locale/UB issues.
  • Test with edge cases: zero exposures, discarding more than exposure, and the 36-exposure jumbo case to confirm discount behavior.

Recommended Answers

All 3 Replies

We don't just solve assigments here! You start it, get some code going, and post specific problems with the code you have. We have to see that you have been making a real effort to solve this problem by yourself. We only give help to cross the few hurdles you meet along your way, we don't just drive you all the way.

BTW: don't post such general titles as "C++ program", try to be more specific about it like "Writing a Photo Store Management Program"

ok will do so..thank you

Here is what i've written so far but i know there's plenty of mistakes in the program as it is not working correctly also.

Hoping to get some help..as i am not really good at doing programming..its only a part of the module i am studying at university.

//calculates the price to be paid for the development of photographs
#include <iostream>

double calcTotal(int exposure)
{
    const double PRICE = 3.40;
    const double DISCOUNT = 0.05;
    double discount, priceBeforeDiscount;
    priceBeforeDiscount = exposure * PRICE;
    discount = priceBeforeDiscount * DISCOUNT;
    return(priceBeforeDiscount - discount);
}   

double calcTotal(int exposure, int number_discarded)
{
    const double PRICE = 3.20;
    const int FREE_PHOTO = 6;
    int numPhoto;
    numPhoto = number_discarded - FREE_PHOTO; 
    return (numPhoto * PRICE);
}


int main ()
{
    using namespace std;
    int exposure = 36;
    int number_discarded;
    double total_price;
    char answer;

    cout << "Do you want jumbo-size photograpths. or normal-size photographs?"
         << "(Enter 'J' for jumbo-size photograph and 'N' for normal size photograph)";
    cin >> answer;

    if (answer == 'J')
        total_price = calcTotal(exposure);
    else 
        cout << "Enter the number of photographs to be discarded: ";
        cin >> number_discarded;
        total_price = calcTotal(exposure,number_discarded);

    cout << "The total price to be paid for the development of photographs is R" << total_price << endl;
    return 0;
}
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.