I'm just a beginner, and I'm completely stuck on my homework... don't be tough, please!
JAVA - eclipse
I have to create a program that emulates an ATM that only gives 20 and 50€ bills:
The 50€ bills have priority (if I want 120, it will be 2 50's and one 20)
I can only use else-if.
Beware, because if I need 60€, it has to be three 20€ bills. Or 110, it can gives me one 50€ and 3 20's...
If I ask something that the ATM can't give with 50's and 20's, it will say it can't.
I got this so far:
System.out.print("Bienvenido de nuevo Sr. Bezos. ¿Qué humilde cantidad le doy? ");
final int dinero = scr.nextInt();
final int b50, b20, r;
b50 = dinero / 50;
r = dinero % 50;
b20 = r / 20;
if (r == 0)
System.out.println("Le daré " + b50 + " billetes de 50 euros.");
else if (r != 0 && dinero - b50 \* 50 - b20 \* 20 != 0 && r / 20 != 0 || dinero % 20 == 0) {
System.out.println("Le daré " + dinero / 20 + " billetes de 20 euros.");
}
if (dinero - b50 \* 50 - b20 \* 20 != 0 && dinero % 20 != 0) {
System.out.println("Le daré " + b50 + " billetes de 50 euros y " + ((dinero - 10) % 20) + " billetes de 20 euros.");
}
else {
System.out.println("Lo siento, Sr. Bezos. Este cajero sólo dispone de billetes de 50€ y de 20€.");
Aucun commentaire:
Enregistrer un commentaire