In: Computer Science
C++:
Write correct C++ code for a nested if-else if-else structure
that will output a message based on the logic below.
A buyer can pay immediately or be billed. If paid immediately, then
display "a 5% discount is applied." If billed, then display "a 2%
discount is applied" if it is paid in 30 days. If between 30 and 60
days, display "there is no discount." If over 60 days, then display
"a 3% surcharge is added to the bill."
You do not need to declare the variables or assign them values; just write the code for the nested if-else structure itself and the cout statements to display the messages only.
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
#include <iostream>
using namespace std;
double processPayment(double total, int action);
int main()
{
double total;
int action;
cout << "Enter total amount to be paid:" << endl;
cin >> total;
cout<<"Enter your action 1. immediately paid 2. Billed and will pay in 30 days 3. Others"<<endl;
cin >> action;
total = processPayment(total, action);
cout <<"Total amount to be paid after applying respective discount :"<<total<<endl;
return 0;
}
double processPayment(double total, int action) {
if(action == 1)
{
total = total - (total * 5.0/100.0);
}
else if(action == 2){
total = total - (total * 2.0/100.0);
}
else
{
total = total + (total * 3.0/100.0);
}
return total;
}
Kindly revert for any queries
Thanks.