[Solved] Total Expenses with C++

Total Expenses: The much awaited event at the entertainment industry every year is the “Screen Awards”. This year the event is going to be organized on December 25 to honour the Artists for their professional excellence in Cinema. The Organizers has this time decided to launch an online portal to facilitate easy booking of the Award show’s tickets.

They specifically wanted to provide an option for bulk booking in the portal, wherein there are many discounts announced. Write a program to help the Organizers to create the portal as per the requirement given below.

Given the ticket cost as ‘X’.
If the number of tickets purchased is less than 50, there is no discount.
If the number of tickets purchased is between 50 and 100 (both inclusive), then 10% discount is offered.
If the number of tickets purchased is between 101 and 200(both inclusive), 20% discount is offered.
If the number of tickets purchased is between 201 and 400(both inclusive), 30% discount is offered.
If the number of tickets purchased is between 401 and 500(both inclusive), 40% discount is offered.
If the number of tickets purchased is greater than 500, then 50% discount is offered.

Input Format:
First line of the input is an integer that corresponds to the cost of the ticket ‘X’.
Second line of the input is an integer that corresponds to the number of tickets purchased.

Output Format:
Output should display a double value, which gives the total expenses in purchasing the tickets after discounts. Display the output correct to 2 decimal places.
Refer sample input and output for formatting specifications.

Sample Input 1:
100
5

Sample Output 1:
500.00

Sample Input 2:
100
300

Sample Output 2:
21000.00

Solution

#include <iostream>
using namespace std;

int main() {
    int cost, num;
    cin >> cost >> num;
    float total = cost * num;
    if (num < 50) {
        printf("%.2f",total);
    } else if (num >= 50 && num <= 100) {
        total = total * 0.9;
        printf("%.2f",total);
    } else if (num >= 101 && num <= 200) {
        total = total * 0.8;
        printf("%.2f",total);
    } else if (num >= 201 && num <= 400) {
        total = total * 0.7;
        printf("%.2f",total);
    } else if (num >= 401 && num <= 500) {
        total = total * 0.6;
        printf("%.2f",total);
    } else {
        total = total * 0.5;
        printf("%.2f",total);
    }
    return 0;

}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *