Restaurant – Lucky Numbers Discount

       Restaurant - Lucky Numbers Discount


Every day in a restaurant two numbers X and Y are considered lucky numbers.
If the bill amount B is divisible by X, then X% discount is offered.
If the bill amount B is divisible by Y, then Y% discount is offered.
If the bill amount B is divisible by both X and Y, then no amount is to be paid.
The program must accept X, Y and B and print the amount to be paid as the output (precision is upto 3 decimal places)
Input Format:
The first line contains B
The second line contains X
The third line contains Y
Output Format:
The first line contains the amount to be paid finally after discount.
Boundary Conditions:
1 <= X,Y <= 50
20 <= B <= 100000
Example Input/Output 1:
Input:
500
20
50
Output:
0.000
Example Input/Output 2:
Input:
100
9
10
Output:
90.000
Code:

#include <iostream>
#include<iomanip>
using namespace std;
int main(int argc, char** argv)
{
int   b,x,y;
float d;
cin>>b>>x>>y;
if(b%x==0&&b%y==0)
    cout<<"0.000";
else if(b%x==0)
    {
        d=b*(x*.01);
        cout<<fixed<<setprecision(3)<<b-d;
    }
else if(b%y==0)
{
    d=b*(y*.01);
    cout<<fixed<<setprecision(3)<<b-d;
}
else
    cout<<fixed<<setprecision(3)<<(float)b;
 }

#v2#v2lancers
2 Comments

Add a Comment

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