I did a program that translates number into roman numbers, and I was about to show it to a friend of mine when the .exe file didn't work. It asked the user which number to put in, and after he put it the program closed. What I don't understand is why it did work after compiling on DevC++, but had a different behavior as a .exe
I found few solutions out there, and the one that worked for me was to add a:
int a;
cin>>a;
Before returning a cero. Now it works. I don't understand how the console doesn't execute the actions given without that. I'm leaving the code here.
#include <iostream>
using namespace std;
int main(){
int numero, unidades, decenas, centenas, millares;
int comprobante;
cout<<"Este programa traduce un numero de 4 cifras a numeros romanos.\nDigite un numero de
maximo cuatro cifras: ";
cin>>numero;
unidades= numero%10;
numero /= 10;
decenas= numero%10;
numero/=10;
centenas= numero%10;
numero/=10;
millares=numero;
comprobante=millares/10;
if(comprobante==0){
cout<<"Su numero traducido a numeros romanos es: ";
switch(millares){
case 1: cout<<"M"; break;
case 2: cout<<"MM"; break;
case 3: cout<<"MMM"; break;
}
switch(centenas){
case 1: cout<<"C"; break;
case 2: cout<<"CC"; break;
case 3: cout<<"CCC"; break;
case 4: cout<<"CD"; break;
case 5: cout<<"D"; break;
case 6: cout<<"DC"; break;
case 7: cout<<"DCC"; break;
case 8: cout<<"DCCC"; break;
case 9: cout<<"CM"; break;
}
switch(decenas){
case 1: cout<<"X"; break;
case 2: cout<<"XX"; break;
case 3: cout<<"XXX"; break;
case 4: cout<<"XL"; break;
case 5: cout<<"L"; break;
case 6: cout<<"LX"; break;
case 7: cout<<"LXX"; break;
case 8: cout<<"LXXX"; break;
case 9: cout<<"XC"; break;
}
switch(unidades){
case 1: cout<<"I"; break;
case 2: cout<<"II"; break;
case 3: cout<<"III"; break;
case 4: cout<<"IV"; break;
case 5: cout<<"V"; break;
case 6: cout<<"VI"; break;
case 7: cout<<"VII"; break;
case 8: cout<<"VIII"; break;
case 9: cout<<"IX"; break;
}
}
else{
cout<<"Te dije de 4 cifras. Por desgraciado me cierro.";
}
int a;
cin>>a;
return 0;
}