ejercicio 10 y corregir 3 y 6

This commit is contained in:
PC de clase committed 2026-09-25 09:14:25 +02:00
1 parent 3d60270af6
commit bd3b1be755
3 files changed
+37 -7

No files matched your search

+17 -6
View File
@@ -11,14 +11,25 @@ void main() {
System.out.println("Cuantos euros quieres sacar?");
int centimos = (int) Math.round(sc.nextDouble() * 100);
for (int i = 0; centimos != 0 && i < monedas.length;) {
int contador = 0;
for (int i = 0; i < monedas.length;) {
int moneda = monedas[i];
if (centimos >= moneda) {
System.out.printf("Dar moneda de %.2f€\n", moneda / 100.0);
centimos -= moneda;
} else
i++;
contador++;
} else{
if (contador > 0){
System.out.printf("Dar %d moneda%s de %.2f€\n", contador, (contador > 1) ? "s" : "", moneda / 100.0);
contador = 0;
}
i++;
}
}
sc.close();
// 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();
}