Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created January 16, 2021 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/73cadd3420aedf757687a5534ab0c2a0 to your computer and use it in GitHub Desktop.
Save parzibyte/73cadd3420aedf757687a5534ab0c2a0 to your computer and use it in GitHub Desktop.
/*
https://parzibyte.me/blog
*/
#include <iostream>
using namespace std;
int main()
{
// La clave correcta
const string claveCorrecta = "1234";
cout << "Bienvenido al cajero automático\n";
cout << "Ingrese la clave: ";
string clave = "";
cin >> clave;
if (clave != claveCorrecta)
{
cout << "Clave incorrecta";
// Con return detenemos la ejecución del programa
return 0;
}
// Si llegamos hasta aquí, podemos estar seguros de que el usuario introdujo la clave correcta
cout << "Clave correcta\nBienvenido\n";
double fondos = 5000; // Simular fondos
string eleccion = "";
// Menú
while (eleccion != "2")
{
// Mostrar fondos
cout << "Fondos disponibles: " << fondos << endl;
// Imprimir menú
cout << "1. Retirar dinero\n2. Salir\nSeleccione: ";
cin >> eleccion;
if (eleccion == "1")
{
// Solicitar cuánto se retira
double retiro;
cout << "Ingrese cantidad a retirar: " << endl;
cin >> retiro;
// Comprobar si puede retirar
if (retiro > fondos || retiro <= 0)
{
cout << "No puede retirar esa cantidad";
}
else
{
// En caso de que sí pueda retirar
cout << "OK. Ha retirado " << retiro << endl;
// Restamos los fondos existentes
fondos = fondos - retiro;
// Y el ciclo sigue...
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment