Here it is the code:
Code:
#include <stdio.h>
int main() {
float cafe=0.27, troco, d_int=2.00;
troco=d_int-cafe;
printf("Moedas do troco:\n");
while (troco>0) {
if ((troco/2.00)>=1.00) {
printf("1x 2 euros\n");
troco-=2.00;
}
else if ((troco/1.00)>=1.00) {
printf("1x 1 euro\n");
troco-=1.00;
}
else if ((troco/0.50)>=1.00) {
printf("1x 50 cêntimos\n");
troco-=0.50;
}
else if ((troco/0.20)>=1.00) {
printf("1x 20 cêntimos\n");
troco-=0.20;
}
else if ((troco/0.10)>=1.00) {
printf("1x 10 cêntimos\n");
troco-=0.10;
}
else if ((troco/0.05)>=1.00) {
printf("1x 5 cêntimos\n");
troco-=0.05;
}
else if ((troco/0.02)>=1.00) {
printf("1x 2 cêntimos\n");
troco-=0.02;
}
else if ((troco/0.01)>=1.00) {
printf("1x 1 cêntimo\n");
troco-=0.01;
}
}
return 0;
}
The variable "troco" reaches 0.00, however the while cycle doesn't break on "troco>0" condition, so it enters in an infinite cycle. I can't tell why.