0

I'm writing a program for my C++ class I've complete the program. but it won't compile. I'm new to programming so I don't really know what I'm doing wrong. If there is anyone on here that can point me in the right direction. Please help me!

Prompt Description: Write a C++ program to calculate free estimate for carpet and furniture cleaning of residential and business customers. The program continues until end of file is reached.

Fro residential customers, specify and update number of small couches ($50 each), large couches ($80 each), rooms ($70 each) and steps ($5 each) until exit is selected. the bill is calculated based on the number of items. If the amount is more than 500 dollars, a discount of 10% is applied to the bill. Then the customer is offered to select from an installment of 1,2,3, or 4 or press 0 to exit. Based on an installment option, the bill is increased slightlenter code herey, and each installment amount is calculated.

For business customers, ask the user to enter the amount of square footage and then the bill is calculated at .45 per square foot.

Here is the code:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std; 


int exit = 0;
int smallcouches = 1;
int largecouches = 2;
int rooms = 3;
int steps = 4;

const float SMALL_COUCH = 50.0;
const float LARGE_COUCH = 80.0;
const float ROOMS = 70.0;
const float STEPS = 5.00;
const float PER_SQUARE_FOOT = 0.45f;
const float DISCOUNT_QUALIFIED = 500.0;
const float DISCOUNT = 0.10f;
const int ONE = 1;
const int TWO = 2;
const int THREE = 3;
const int FOUR = 4;
const float RATEONE = 0.0f;
const float RATETWO = 0.0535f;
const float RATETHREE = 0.055f;
const float RATEFOUR = 0.0575f;

float billAmount;

float ResidentialEstimate(float SMALL_COUCH, float LARGE_COUCH, float ROOMS, float STEPS, float DISCOUNT_QUALIFIED);
void GetResidentialItems(int& smallcouches, int& largecouches, int& rooms, int& steps);
void InstallmentPlan(float billAmount);
void BusinessEstimate(float PER_SQUARE_FOOT);

int main()
{
    cout << fixed << showpoint << setprecision(2);
    int customerType, residential_customer, business_customer;
    char B, b, R, r; 
    residential_customer = R || r; 
    business_customer = B || b; 

    cout << "Enter customer type: R, r (Residential) or B, b (Business): "; 
    cin >> customerType; //Enter customer type 
    cout << endl; 

    while (cin) //While there is input to read 
    {
        if (customerType == R || customerType == r) //if residential customer 
        {
            ResidentialEstimate(SMALL_COUCH, LARGE_COUCH, ROOMS, STEPS, DISCOUNT_QUALIFIED); // call function ResidentialEstimate 
            InstallmentPlan(billAmount); // all function Installmentplan 
        }
        else if (customerType == B || customerType == b) //else if business customer 
        {
            BusinessEstimate(PER_SQUARE_FOOT); //call function BusinessEstimate 
        }

        cout << "Enter customer type: R, r (Residential) or B, b (Business): ";
        cin >> customerType; // Enter cutomer type 
        cout << endl;
    }

    return 0;
}

float ResidentialEstimate(float SMALL_COUCH, float LARGE_COUCH, float ROOMS, float STEPS, float DISCOUNT_QUALIFIED)
{
    GetResidentialItems(smallcouches, largecouches, rooms, steps); //Call function GetResidentialItems to get items to clean
    billAmount = (SMALL_COUCH + LARGE_COUCH + ROOMS + STEPS); //Calculate the bill amount 
    if (billAmount > 500) //if bill amount is more than 500 dollars 
    {
        DISCOUNT_QUALIFIED = billAmount * 0.10f; 
        billAmount = billAmount - DISCOUNT_QUALIFIED; //Apply a discount of 10% to the bill amount
    }
    return billAmount; //return bill Amount 
}

void GetResidentialItems(int& smallcouches, int& largecouches, int& rooms, int& steps)
{
    int count; 
    int choice = smallcouches || largecouches || rooms || steps; 
    //Ask user to select an item to update or press 0 to exit
    cout << "0. Exit, 1. Small Couches, 2. Large Couches, 3. Rooms, 4. Steps " << endl;
    cout << "Enter one of the above choices: ";
    cin >> choice; 
    cout << endl; 
    while (choice > 0)  //while user hasn't pressed 0
    {
        choice = count;
        cout << "Please enter the number of " << choice; //ask the user to enter a number from the item selected
        cin >> count;
        cout << endl;
        //Show the current selections and numbers 
        cout << "Current selections: " << count << " Small Couches, " << count << " Large Couches, " << count << " Rooms, " << count << " Steps.";
        //Ask user to select an item to update or press 0 to exit 

        choice = 0;
        count = 0; 

        cout << "0. Exit, 1. Small Couches, 2. Large Couches, 3. Rooms, 4. Steps " << endl;
        cout << "Enter one of the above choices: ";
        cin >> choice;
        cout << endl;
    }
}

void InstallmentPlan(float billAmount)
{
    int num; 
    int installment = 0; 
    int bill = 0; 
    //Ask user to select number of installments or 0 to exit 
    cout << "Please enter the desired number of instalments (1, 2, 3, or 4) or 0 to exit : ";
    cin >> num;
    cout << endl;
    while (num > 0) //while user hasn't pressed 0 
    {
        //calculate the installments
        if (num == 1)
            installment = billAmount;
        else if (num == 2)
        {
            bill = billAmount * 0.0535f;
            installment = bill / num;
        }
        else if (num == 3)
        {
            bill = billAmount * 0.055f;
            installment = bill / num;
        }
        else if (num == 4)
        {
            bill = billAmount * 0.0575f;
            installment = bill / num;
        }

        cout << "With " << num << " installment your bill of " << billAmount << " will be worth " << bill << "." << endl;
        cout << "Each installment will be worth " << installment << endl;

        //Ask user to select number of installments or 0 to exit 
        cout << "Please enter the desired number of instalments (1, 2, 3, or 4) or 0 to exit : ";
        cin >> num;
        cout << endl;
    }
}

void BusinessEstimate(float squarefootage)
{
    //Ask user for the square footage
    cout << " Enter the approximate square footage: ";
    cin >> squarefootage; 
    cout << endl; 
    //Calculate the bill amount 
    billAmount = squarefootage * PER_SQUARE_FOOT; 
    cout << "Your free Business Customer Estimate for " << squarefootage << "square footage = " << billAmount; 
}
  • 2
    Please see [mre] for help narrowing down the problem and edit your question to include the error message. – JaMiT Mar 19 '20 at 04:55
  • And when you include the error message, include the *exact* error message as it appears in your console. – JohnFilleau Mar 19 '20 at 05:05
  • 2
    If using gcc/clang, add `-Wall -Wextra -pedantic -Wshadow` options to your compile string, if using VS add `/W3`, for other compilers, check how to enable warnings (and specifically warn on shadowed variables). Do not accept code until it compiles without warning. Your error is `"error: ‘int exit’ redeclared as different kind of symbol"` -- there is an `exit()` function that is fundamental to C/C++. – David C. Rankin Mar 19 '20 at 05:05
  • There are some compilation errors in your code. Your compiler will be able to tell you what and where the error is. – Wander3r Mar 19 '20 at 05:09
  • I would also suggest a review of [Are global variables bad?](https://stackoverflow.com/q/484635/3422102) and [Do global variables mean faster code?](https://stackoverflow.com/q/3952670/3422102). Bottom line your use of global variables is the root of virtually all of your shadowed variable problems. In each function parameter list (which is a declaration of the variable for the function) you re-declare many of the variables you declare globally. That defeats the purpose of passing the variables as parameters in the first place. – David C. Rankin Mar 19 '20 at 05:21
  • I'm voting to close this question as off-topic because "this is clearly homework." What you need to do now is to take these problems **to your instructor.** Your teacher really needs to hear from you and other students, to know when a topic needs more explaining. (S)He can also help you get this program finished. And, ***persevere!*** It really does get easier with time, frustrating though it is at the beginning. – Mike Robinson Mar 19 '20 at 05:31

0 Answers0