Answer to Question #333104 in C++ for Padi

Question #333104

A bookshop gives discount to customers as follows: • Students get 10% discount, • Book dealers get 12% discount and • Pensioners get 15% discount. • All other customers get 10% discount only if their total purchases are more than R200. You are requested to write two versions of a program that calculates and displays the final amount that is due, after discount. (i) The first version of the program uses a switch statement to implement the above program. (ii) The second version of the program uses nested-if statements. Hint: Use the following variables: float amount; // the amount due before discount char customer Type; // the type of customer: 'S' (student) or // 'D' (dealer) or 'P' (pensioner) or


1
Expert's answer
2022-04-28T13:22:48-0400
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    float amount;
    char Type;
    int discount=0;
    
    cout << "Enter customer Type (S -  student, D - dealer, P - pensioner): ";
    cin >> Type;
    cout<<"Enter amount: ";
    cin>>amount;
    
    switch(Type){
        case 'S':
            discount=10;
            break;
        case 'D':
            discount=12;
            break;    
        case 'P':
            discount=15;
            break;
        default:
            if(amount>200)    
                discount=10;                
    }
    amount = amount-(amount*discount)/100;
    cout<<fixed<<setprecision(2)<<amount<<endl;
    return 0;
}


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

int main() {
    float amount;
    char Type;
    int discount=0;
    
    cout << "Enter customer Type (S -  student, D - dealer, P - pensioner): ";
    cin >> Type;
    cout<<"Enter amount: ";
    cin>>amount;
    
    if(Type=='S')
        discount=10;
    else if(Type=='D')
        discount=12;
    else if(Type=='P')     
        discount=15;
    else
        if(amount>200)    
            discount=10;
                            
    amount = amount-(amount*discount)/100;
    cout<<fixed<<setprecision(2)<<amount<<endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS