0

Can someone tell me what I'm doing wrong? Everything seems to be ok to me? 🥺

/*If you were to visit houses, several give you candy, two houses give you dollars, and one house gives you a toothbrush. At the end of the tour. What is the probability (in %)of taking 1 dollar bill out of my bag? Example If you visited four houses, one would be candy, two would be dollars, and one would be a toothbrush. A 2 in 4 chan*/import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int houses = input.nextInt(); if(houses>=3){ double parte=houses-2; double total=houses; double uno=1; double division=(uno-parte/total)*100; int redondeo=(int)(division*10); if(redondeo%10>=5){ int num=(int)division; System.out.println(num+1); } else{ int num=(int)division; System.out.println(num); } } } }

8th Jan 2023, 2:18 PM
Genniell Vergaray
Genniell Vergaray - avatar
2 Antworten
+ 2
Hi Genniell just few tips to get better help, its better to post a url to your code instead of posting it here in clear, the name of variables must be meaningful, also add some comments to your code, I think that's it 😁 about the problem: there is one house gives candy + 2 dollar bills and the fourth gives toothbrush, if there is fifth house, will gives candy,.. and so one for simplicity : (. means no dollar) (* means dollar bill) h1 h2 h3 h4 h5 . * * . . so if there is 5 houses , the percentage will be ~ 5/2 wich will be 100/(5/2) wich is 200/5; so in general if you visited N houses the percentge will be 200/N; so this you should round it up to the nearest integer.
8th Jan 2023, 4:51 PM
Amine Laaboudi
Amine Laaboudi - avatar
+ 1
Thank you very much I will take your advice into account
8th Jan 2023, 6:01 PM
Genniell Vergaray
Genniell Vergaray - avatar