Computer Science, asked by shridharofficial, 2 months ago

While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than 1000. If the quantity and price per item are input, write a program to calculate the total expenses.

Input Format

The first line contains an integer T, total number of test cases. Then follow T lines, each line contains integers quantity and price.

Constraints

1 ≤ T ≤ 1000
1 ≤ quantity,price ≤ 100000
Output Format

Output the total expenses while purchasing items.

Sample Input 0

3
100 120
10 20
1200 20
Sample Output 0

12000.000000
200.000000
21600.000000

-------------------------------------------------------------------------------------

this is my solution but it is failing 2 test cases , and i dont know why.

import java.io.*;
import java.util.*;
import java.lang.*;

public class Solution
{
public static void main( String[] args )
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T-- >0){
int quan = sc.nextInt();
int price = sc.nextInt();
if(quan < 1000){
float expenses = quan*price;
System.out.printf("%6f \n" , expenses);
}
else if(quan == 0){
System.out.printf("%6f",0);
}
else{
float discount = (quan * price)/10;
float expenses = (quan * price) - discount;
System.out.printf("%6f \n" , expenses);
}
}
}
}

Answers

Answered by ngtime
1

Answer:

ans is 100

Explanation:

While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than 1000. If the quantity and price per item are input, write a program to calculate the total expenses.

Input Format

The first line contains an integer T, total number of test cases. Then follow T lines, each line contains integers quantity and price.

Constraints

1 ≤ T ≤ 1000

1 ≤ quantity,price ≤ 100000

Output Format

Output the total expenses while purchasing items.

Sample Input 0

3

100 120

10 20

1200 20

Sample Output 0

12000.000000

200.000000

21600.000000

-------------------------------------------------------------------------------------

this is my solution but it is failing 2 test cases , and i dont know why.

import java.io.*;

import java.util.*;

import java.lang.*;

public class Solution

{

public static void main( String[] args )

{

Scanner sc = new Scanner(System.in);

int T = sc.nextInt();

while(T-- >0){

int quan = sc.nextInt();

int price = sc.nextInt();

if(quan < 1000){

float expenses = quan*price;

System.out.printf("%6f \n" , expenses);

}

else if(quan == 0){

System.out.printf("%6f",0);

}

else{

float discount = (quan * price)/10;

float expenses = (quan * price) - discount;

System.out.printf("%6f \n" , expenses);

}

}

}

}

Similar questions