Skip to content

Instantly share code, notes, and snippets.

@jorarmarfin
Created November 17, 2024 21:14
Show Gist options
  • Save jorarmarfin/855c4b11903cb540f5df555a125f8d2d to your computer and use it in GitHub Desktop.
Save jorarmarfin/855c4b11903cb540f5df555a125f8d2d to your computer and use it in GitHub Desktop.
#include "miniwin.h"
#include <string>
using namespace miniwin;
using namespace std;
string convertirARomanos(int numero) {
string resultado = "";
int valores[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
string simbolos[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
for (int i = 0; i < 13; i++) {
while (numero >= valores[i]) {
resultado += simbolos[i];
numero -= valores[i];
}
}
return resultado;
}
int main() {
int t = tecla();
vredimensiona(500, 500);
string numero = "";
string numeroRomano = "";
while (t != ESCAPE) {
borra();
// Si la tecla presionada es un número (código ASCII entre '0' y '9')
if (t >= '0' && t <= '9') {
numero = static_cast<char>(t); // Convertir el código ASCII en carácter y almacenarlo
int valor = t - '0'; // Convertir el carácter en su valor numérico
numeroRomano = convertirARomanos(valor); // Convertir el número a romano
}
color(BLANCO);
texto(10, 10, "Selecciono el numero: " + numero); // Mostrar el número en la parte superior izquierda
texto(10, 30, "En romano: " + numeroRomano); // Mostrar el número romano
refresca();
espera(30);
t = tecla();
}
vcierra();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment