What's new

C & C++ Pa Check po ng Code ko

Rednevin

Honorary Poster
Joined
Dec 5, 2017
Posts
269
Reaction
40
Points
212
Age
25
C++:
// Lab 5-3: Modify
/* Modify the Heaton Boutique program from Lab 5-2 to give a 10% discount to members of the store’s Premier Club, and a 5% discount to all other customers.*/
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    //My Variables
    const double DISCOUNT_RATE_MEMBER = 0.10;
    const double DISCOUNT_RATE_NONMEMBER = 0.05;
    const double SHIPPING_RATE1 = 0.99;
    const double SHIPPING_RATE2 = 4.99;
    double TOTAL_AMT;
    char MEMBER;
    //Enter Initial Purchase Amount
    cout << "Initial Purchase Amount: $";
    cin >> TOTAL_AMT;
    //Validate the Initial Purchase Amount
    if (TOTAL_AMT < 0) {
        cout << "Invalid input!" << endl;
        cout << "Initial Purchase Amount: ";
        cin >> TOTAL_AMT;
        if (TOTAL_AMT < 0) {
        cout << "Invalid input!" << endl;
        cout << "Initial Purchase Amount: ";
        cin >> TOTAL_AMT;
        }if (TOTAL_AMT < 0) {
        cout << "Invalid input!" << endl;
        cout << "Initial Purchase Amount: ";
        cin >> TOTAL_AMT;
        }if (TOTAL_AMT < 0) {
        cout << "Invalid input! Please re-run the program.";
        return 0;
        }
    }//end if
    //Enter for Member and Non-Member Customer
    cout << "Member of 'Premier Club' store? (Type <Y> or <N>) ";
    cin >> MEMBER;
    //Validate the input for Member and Non-Member Customer
    if (toupper(MEMBER) == 'Y') {
        if (TOTAL_AMT >= 100) {
            //Compute Total Amount Purchased
            TOTAL_AMT -= TOTAL_AMT * DISCOUNT_RATE_MEMBER;
            TOTAL_AMT += SHIPPING_RATE1;
            //Display Output
            cout << fixed << setprecision(2);
            cout << "Total Purchased Amount with Membership Discount and Shipping Fee: $" << TOTAL_AMT << endl;
            return 0;
        }
        else {
            //Compute for else statement
            TOTAL_AMT -= TOTAL_AMT * DISCOUNT_RATE_MEMBER;
            TOTAL_AMT += SHIPPING_RATE2;
            //Displaying Output
            cout << fixed << setprecision(2);
            cout << "Total Purchased Amount with Membership Discount and Shipping Fee: $" << TOTAL_AMT << endl;
            return 0;
        }
    } //end if
    else if (toupper(MEMBER) == 'N') {
        if (TOTAL_AMT >= 100) {
        //Compute for if statement
        TOTAL_AMT -= TOTAL_AMT * DISCOUNT_RATE_NONMEMBER;
        TOTAL_AMT += SHIPPING_RATE1;
        //Display Output
        cout << fixed << setprecision(2);
        cout << "Total Purchased Amount with Non-Member Discount and Shipping Fee: $" << TOTAL_AMT << endl;
        return 0;
        }
        else {
        TOTAL_AMT -= TOTAL_AMT * DISCOUNT_RATE_NONMEMBER;
        TOTAL_AMT += SHIPPING_RATE2;
        cout << fixed << setprecision(2);
        cout << "Total Purchased Amount with Non-Member Discount and Shipping Fee: $" << TOTAL_AMT << endl;
        return 0;
        }
    } //end else if
    else {
        cout << "Wrong Input! Please Try Again.";
    } // end else
    return 0;
}

Pano po ito ayusin itong output ko po naka endl napo pero naka oneline parin po dito sa JDoodle na compiler ito po kase na compiler pinapagamit samin ng prof namin.
Output sa JDoodle:
1666183768892.png
 

Attachments

Similar threads

Back
Top