0
What am I doing wrong. It’s about Halloween candy practice.
#include <iostream> #include <cmath> using namespace std; int main() { int houses; int dollar = 2; int chances; cin>>houses; chances = dollar*100/houses; cout << chances; return 0; }
5 ответов
+ 4
You could use the % operator to check if the result is a decimal.
If it is a decimal, you round up to the next integer.
round up & round are 2 different meanings.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int houses;
int dollar = 2;
int chances;
cin>>houses;
chances = dollar*100/houses;
if((dollar*100) %houses==0){
cout << chances;
} else {
cout << chances +1;
}
return 0;
}
+ 3
You have to roundup the value see input and output format
+ 3
ceil(dollar*100.0/houses)
+ 1
Thanks a lot. I understood both methods.
0
Still not working. I get the same error.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int houses;
int dollar = 2;
double chances;
int result;
cin>>houses;
chances = dollar*100/houses;
result = round(chances);
cout << result;
return 0;
}