Q.3 A shopkeeper announces a package for customers that he will give 10 % discount on all bills and if a bill amount is greater than 5000 then a discount of 15 %. Write a C++ program which takes amount of the bill from user and calculates the payable amount by applying the above discount criteria and display it on the screen.

A shopkeeper announces a package for customers that he will give 10 % discount on all bills and if a bill amount is greater than 5000 then a discount of 15 %. Write a C++ program which takes amount of the bill from user and calculates the payable amount by applying the

Here's a step-by-step solution to the problem:

Step 1: Start the program.

Step 2: Declare the required variables: billAmount, payableAmount.

Step 3: Take input from the user for the bill amount and store it in the billAmount variable.

Step 4: Check if the bill amount is greater than 5000.

Step 5: If the bill amount is greater than 5000, calculate the payable amount by applying a discount of 15% to the bill amount using the formula:
payableAmount = billAmount - (billAmount * 0.15)

Step 6: If the bill amount is less than or equal to 5000, calculate the payable amount by applying a discount of 10% to the bill amount using the formula:
payableAmount = billAmount - (billAmount * 0.10)

Step 7: Display the payable amount on the screen.

Step 8: End the program.

Here's the C++ code for the program:

```cpp
#include <iostream>
using namespace std;

int main() {
// Step 2: Declare the required variables
float billAmount, payableAmount;

// Step 3: Take input from the user
cout << "Enter the bill amount: ";
cin >> billAmount;

// Step 4: Check if the bill amount is greater than 5000
if (billAmount > 5000) {
// Step 5: Calculate payable amount with 15% discount
payableAmount = billAmount - (billAmount * 0.15);
} else {
// Step 6: Calculate payable amount with 10% discount
payableAmount = billAmount - (billAmount * 0.10);
}

// Step 7: Display the payable amount
cout << "Payable amount: " << payableAmount << endl;

// Step 8: End the program
return 0;
}
```

Hope this helps!

To write a C++ program that calculates the payable amount with the given discount criteria, you can follow these steps:

1. Start by including the necessary header files, such as iostream for input/output operations.
```
#include <iostream>
using namespace std;
```

2. Declare a function to calculate the payable amount based on the given discount criteria. You can name the function `calculatePayableAmount` and it will take the bill amount as a parameter and return the payable amount as a result.

```
float calculatePayableAmount(float billAmount) {
float payableAmount;

if (billAmount > 5000) {
payableAmount = billAmount - (billAmount * 0.15); // 15% discount
} else {
payableAmount = billAmount - (billAmount * 0.10); // 10% discount
}

return payableAmount;
}
```

3. In the `main()` function, prompt the user to enter the bill amount and store it in a variable.

```
int main() {
float billAmount;

cout << "Enter the bill amount: ";
cin >> billAmount;
```

4. Call the `calculatePayableAmount()` function with the user input as the argument and store the result in a variable.

```
float payableAmount = calculatePayableAmount(billAmount);
```

5. Finally, display the payable amount on the screen.

```
cout << "Payable amount: " << payableAmount << endl;

return 0;
}
```

The complete program will look like this:

```cpp
#include <iostream>
using namespace std;

float calculatePayableAmount(float billAmount) {
float payableAmount;

if (billAmount > 5000) {
payableAmount = billAmount - (billAmount * 0.15); // 15% discount
} else {
payableAmount = billAmount - (billAmount * 0.10); // 10% discount
}

return payableAmount;
}

int main() {
float billAmount;

cout << "Enter the bill amount: ";
cin >> billAmount;

float payableAmount = calculatePayableAmount(billAmount);

cout << "Payable amount: " << payableAmount << endl;

return 0;
}
```

By following these steps, you will have a C++ program that calculates the payable amount based on the given discount criteria and displays it on the screen.