July 31, 2017

# 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.

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)

**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

Java

import java.util.*;

public class Hello {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int billAmount = sc.nextInt();

int xNumber = sc.nextInt();

int yNumber = sc.nextInt();

double amountPaid = 0.000f;

if(billAmount%xNumber==0&&billAmount%yNumber==0)

{

System.out.format("%.3f",amountPaid);

}

else if(billAmount%xNumber==0)

{

double discount = (double) billAmount * ((double)xNumber/(double)100);

amountPaid = billAmount-discount;

System.out.format("%.3f",amountPaid);

}

else if(billAmount%yNumber==0)

{

double discount = (double)billAmount * ((double)yNumber/(double)100);

amountPaid = billAmount-discount;

System.out.format("%.3f",amountPaid);

}

else

{

amountPaid = new Float(billAmount);

System.out.format("%.3f",amountPaid);

}

}

}

Gud Job!!