+ 1

[solved ] Please need your help .The following problem in the community section is displaying that there is a bug in my code .

You go trick or treating with a friend and all but three of the houses that you visit are giving out candy. One house that you visit is giving out toothbrushes and two houses are giving out dollar bills. Task Given the input of the total number of houses that you visited, what is the percentage chance that one random item pulled from your bag is a dollar bill? Input Format An integer (>=3) representing the total number of houses that you visited. Output Format A percentage value rounded up to the nearest whole number. Sample Input 4 Sample Output 50 __________________________________________ #include <iostream> #include<cmath> using namespace std; int main() { int houses; cin>>houses; int a ; a = round(200.0/houses); cout<<a; return 0; }

18th Dec 2020, 11:51 AM
Genio Cerveaus
Genio Cerveaus - avatar
3 Respuestas
+ 7
Use ceil() instead of round() { as you are told to round up instead of round off in question } Here is the fix 👇 https://code.sololearn.com/cwieH8qZX6sk/?ref=app
18th Dec 2020, 11:59 AM
Arsenic
Arsenic - avatar
+ 1
Thank you Arsenic it worked .
18th Dec 2020, 12:04 PM
Genio Cerveaus
Genio Cerveaus - avatar
0
import math houses=int(input()) print(math.ceil(2*(100/houses)))
7th May 2022, 7:56 PM
Pavan Kalyan Gali