+ 1
Here is the full code, please i need help!!
int main() { float houses; float dollar; cin >> houses; //your code goes here { dollar = (((houses - (houses - 2))) / houses) * 100; if (dollar == (int)dollar) { cout << dollar; } else cout << (int)dollar + 1; } return 0; }
3 Answers
+ 2
Note that the dollar calculation can be simplified to (2.0/houses)*100.0, and further to 200.0/houses.
The if/else statement is there to find the ceiling of dollar. If dollar is already an integer value, then print it. Else, print the next higher integer.
Here is a simpler version that might be easier to understand:
#import <math>
.
.
.
cin >> houses;
cout << (int)ceil(200.0/houses);
+ 1
Baiscally its just rounding the dollar to the nearest 1
So if dollar is 16.5 then round to 17