samedi 15 octobre 2016

Having trouble getting my error message to nest properly

I'm having trouble getting the error message for when a user-entered value is equal to or less than zero to nest properly. I'm not sure where it should go, or if I need to do something else entirely. Any help would be appreciated. Below is my code as it stands.

Instructions: "A software company sells a package that retails for $99. Quantity discounts are given according to the following:" 10-19 = 20% Discount,20-49 = 30% Discount, 50-99 = 40% Discount, 100+ = 50% Discount. Write a program that asks for the number of units purchased and computes the total cost of the purchase. Input Validation: Decide how the program should handle an input of less than 0.

#include <iostream>
#include <iomanip> // needed for setprecision
#include <stdio.h>

using namespace std; // need to use cout, cin, etc.

int main()
{
double quantity, package = 99.00, initialPrice, discPrice, discount, calcDiscount, percent; // using double here because future multiplication by .2

cout << "This program will calculate how much of a discount you may receive,\nbased on how many software packages you buy.\n\n";
cout << "How many software packages do you intend to purchase?\n\n";
cin >> quantity;
{
    if (quantity <= 0)
         cout << "\nThat is not an acceptable amount. Please re-run the program with a amount greater than zero.\n\n";
}
    if ( quantity >= 10 && quantity <= 19)
        discount = 0.2, percent = 20;
    else if ( quantity >= 20 && quantity <= 49)
        discount = 0.3, percent = 30;
    else if ( quantity >= 50 && quantity <= 99)
        discount = 0.4, percent = 40;
    else if ( quantity >= 100 )
        discount = 0.5, percent = 50;
    else if (quantity <10 && quantity >=1)
        discount = 0, percent = 0;
    {
        initialPrice = package * quantity;
        calcDiscount = (discount * package * quantity);
        discPrice = initialPrice - calcDiscount;
        cout << "\nThe total price for " << quantity << " software packages, minus a " << percent << "% discount of $";
        cout << fixed << showpoint << setprecision(2) << calcDiscount << ",";
        cout << " is $" << fixed << showpoint << setprecision(2) << discPrice << ".\n\n";
    }
return 0;
}

Aucun commentaire:

Enregistrer un commentaire