0

Only first two testcases executed correctly(super sale question : type=medium)

What may be wrong

25th Feb 2023, 5:07 AM
Ullas A
Ullas A - avatar
8 ответов
+ 3
Items are not fixed in 3 number i guess. There may be more. num2, num3 are conditions should be changed to num2==greater, num3==greater.
25th Feb 2023, 10:09 AM
Jayakrishna 🇮🇳
+ 2
What's the task?
25th Feb 2023, 9:44 AM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Ullas A The task doesn't determine the number of items, so a fixed number of variables won't work. Go for an array of the like. Also, the row of comparisons to find the most expensive item tends to get horrible as you have more items. Use a loop instead. As a general rule, making code more generic makes it more robust too.
26th Feb 2023, 11:06 AM
Emerson Prado
Emerson Prado - avatar
+ 1
Thank you Emerson Prado it helped me!! Thanks for guiding
27th Feb 2023, 2:27 AM
Ullas A
Ullas A - avatar
0
import java.util.Scanner; import java.lang.Math; public class Program { public static void main(String[] args) { double tax = 0.07; double discount = 0.3; Scanner sc = new Scanner(System.in); String[] str = sc.nextLine().split(","); double num1 = Double.parseDouble(str[0]); double num2 = Double.parseDouble(str[1]); double num3 = Double.parseDouble(str[2]); double greater = (num3>(num1>num2?num1:num2))?num3:(num1>num2?num1:num2); num1= (num1==greater)?0:num1; num2= (num1==greater)?0:num2; num3= (num1==greater)?0:num3; double tot = (num1+num2+num3)*(discount); double total = (tot*tax)+tot; System.out.print((int)Math.floor(total)); } }
25th Feb 2023, 5:08 AM
Ullas A
Ullas A - avatar
0
Your favorite store is having a sale! You pay full price for the most expensive item that you get, but then you get 30% off of everything else in your purchase! How much are you going to save? Sales tax is 7%. Also, you leave anything below a dollar in your saving as a tip to the seller. If your saving is a round amount, you don't leave any tips. Task: Given the prices of items you want to purchase, determine how much you will save during your shopping! Input Format: An string of numbers separated by commas that represent the prices for all of the items that you want to purchase (without tax). Output Format: An integer number that represents the total savings that you got for shopping during the sale. Sample Input: 100.25,80.99,40.00 Sample Output: 38
25th Feb 2023, 9:51 AM
Ullas A
Ullas A - avatar
0
You were right I changed it but still 4 test cases are failed
25th Feb 2023, 10:18 AM
Ullas A
Ullas A - avatar
0
Also you are finding the total with discount. and displaying. I think, that total savings, it asking to find which is "30% of total price , excluded max item price" ie. Math.floor( (80.99 + 40.00) * 0.3 + (include tax) ) = 38 Or total price without discount - total price with discount.
26th Feb 2023, 2:08 PM
Jayakrishna 🇮🇳