-
-
Save parzibyte/27a5cc33bf77a58559624878cd1358d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Si elige 1, entonces solicitar número de artículo y cantidad | |
if (eleccion == "1") | |
{ | |
int numeroArticulo; | |
cout << "Ingrese el número de artículo: "; | |
cin >> numeroArticulo; | |
// Necesitamos el índice del arreglo, que sería restarle 1 al número que elige el usuario pues los arreglos comienzan a contar en 0 | |
int indice = numeroArticulo - 1; | |
// Validamos si el número de artículo está entre 0 y 3 | |
if (indice >= 0 && indice <= 3) | |
{ | |
// Solicitamos cantidad | |
int cantidad; | |
cout << "Ingrese la cantidad que compra: "; | |
cin >> cantidad; | |
// Validar si la cantidad es correcta | |
if (cantidad > cantidades[indice]) | |
{ | |
cout << "No hay suficiente existencia" << endl; | |
} | |
else | |
{ | |
// En caso de que sí haya suficiente existencia, extraemos el costo | |
double costo = costos[indice]; | |
// Sacamos el costo total | |
double total = costo * cantidad; | |
// Imprimimos | |
cout << "========================================" << endl; | |
cout << "Usted ha comprado " << articulos[indice] << " X " << cantidad << endl; | |
cout << "Total: " << total << endl; | |
cout << "GRACIAS POR SU COMPRA" << endl; | |
cout << "========================================" << endl; | |
// Y restamos la cantidad en el arreglo | |
cantidades[indice] = cantidades[indice] - cantidad; | |
} | |
} | |
else | |
{ | |
// Caso contrario, imprimimos que no es un artículo válido | |
cout << "Número de artículo " << numeroArticulo << " inválido" << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment