Merge branch 'master' of https://git.troyale.xyz/troyale/Tema-2_alternativas-y-bucles
This commit is contained in:
commit
d459661d0a
1 file changed
+4
-9
@@ -14,22 +14,17 @@ void main() {
|
|||||||
int contador = 0;
|
int contador = 0;
|
||||||
for (int i = 0; i < monedas.length;) {
|
for (int i = 0; i < monedas.length;) {
|
||||||
int moneda = monedas[i];
|
int moneda = monedas[i];
|
||||||
if (centimos >= moneda) {
|
if (centimos < moneda) {
|
||||||
centimos -= moneda;
|
|
||||||
contador++;
|
|
||||||
} else{
|
|
||||||
if (contador > 0){
|
if (contador > 0){
|
||||||
System.out.printf("Dar %d moneda%s de %.2f€\n", contador, (contador > 1) ? "s" : "", moneda / 100.0);
|
System.out.printf("Dar %d moneda%s de %.2f€\n", contador, (contador > 1) ? "s" : "", moneda / 100.0);
|
||||||
contador = 0;
|
contador = 0;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
} else{
|
||||||
|
centimos -= moneda;
|
||||||
|
contador++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Iteración final
|
|
||||||
if (contador > 0){
|
|
||||||
System.out.printf("Dar %d moneda%s de %.2f€\n", contador, (contador > 1) ? "s" : "", monedas[monedas.length-1] / 100.0);
|
|
||||||
contador = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
sc.close();
|
sc.close();
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user