hey guys, I want to write a program to transform numbers to letters

if I write 652 I want the program to print six hundred fifty two

I have written this but I have a problem. For the 652... I get six hundred 5 2.

The numbers are in spanish :p

help!

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <iomanip>

 using std::setw;
 using std::setfill;

using namespace std;

int main ()
{
  int n, uni, cent, dece, mil;
  
  cout<<"Ingrese un numero del 1 al 9999"<<endl;
  cin>>n;
  unidad=(n%10);
  decena=(n%100)/10;
  centena=(n%1000)/100;
   millar=(n%10000)/1000;
  

  if (n==1){
  cout<<"uno"<<endl;}
  if (n==2){
  cout<<"dos"<<endl;}
  if (n==3){
  cout<<"tres"<<endl;}
  if (n==4){
  cout<<"cuatro"<<endl;}
  if (n==5){
  cout<<"cinco"<<endl;}
  if (n==6){
  cout<<"seis"<<endl;}
  if (n==7){
  cout<<"siete"<<endl;}
  if (n==8){
  cout<<"ocho"<<endl;}
  if (n==9){
  cout<<"nueve"<<endl;}
  if (n==10){
  cout<<"diez"<<endl;}
  if (n==11){
  cout<<"once"<<endl;}
  if (n==12){
  cout<<"doce"<<endl;}
  if (n==13){
  cout<<"trece"<<endl;}
  if (n==14){
  cout<<"catorce"<<endl;}
  if (n==15){
  cout<<"quince"<<endl;}
  if (n==16){
  cout<<"dieciseis"<<endl;}
  if (n==17){
  cout<<"diecisiete"<<endl;}
  if (n==18){
  cout<<"dieciocho"<<endl;}
  if (n==19){
  cout<<"diecinueve"<<endl;}
  if (n==20){
  cout<<"veinte"<<endl;}
  if (n==21){
  cout<<"veinte y uno"<<endl;}
  if (n==22){
  cout<<"veinte y dos"<<endl;}
  if (n==23){
  cout<<"veinte y tres"<<endl;}
  if (n==24){
  cout<<"veinte y cuatro"<<endl;}
  if (n==25){
  cout<<"veinte y cinco"<<endl;}
  if (n==26){
  cout<<"veinte y seis"<<endl;}
  if (n==27){
  cout<<"veinte y siete"<<endl;}
  if (n==28){
  cout<<"veinte y ocho"<<endl;}
  if (n==29){
  cout<<"veinte y nueve"<<endl;}
 
  if (n/10==3){
  cout<<"treinta y "<<unidad<<endl;}
  if (n/10==4){
  cout<<"cuarenta y "<<unidad<<endl;}
  if (n/10==5){
  cout<<"cincuenta y "<<unidad<<endl;}
  if (n/10==6){
  cout<<"sesenta y "<<unidad<<endl;}
  if (n/10==7){
  cout<<"setenta y "<<unidad<<endl;}
  if (n/10==8){
  cout<<"ochenta y "<<unidad<<endl;}
  if (n/10==9){
  cout<<"noventa y "<<unidad<<endl;}
  
  if (n==100){
  cout<<"cien"<<endl;}
  if (n<200&& n>=100){
  cout<<"cientos"<<endl;}
  if (n<300&& n>=200){
  cout<<"doscientos"<<decena<<"y"<<unidad<<endl;}
  if (n<400&& n>=300){
  cout<<"trescientos"<<decena<<"y"<<unidad<<endl;}
  if (n<500&& n>=400){
  cout<<"cuatrocientos"<<decena<<"y"<<unidad<<endl;}
  if (n<600&& n>=500){
  cout<<"quinientos"<<decena<<"y"<<unidad<<endl;}
  if (n<700&& n>=600){
  cout<<"seiscientos"<<decena<<"y"<<unidad<<endl;}
  if (n<800&& n>=700){
  cout<<"setecientos"<<decena<<"y"<<unidad<<endl;}
  if (n<900&& n>=800){
  cout<<"ochocientos"<<decena<<"y"<<unidad<<endl;}
  if (n<1000&& n>=900){
  cout<<"novecientos"<<decena<<"y"<<unidad<<endl;}
  if (n<2000&& n>=1000){
  cout<<"mil"<<endl;}
  if (n<10000&& n>=2000){
  cout<<"dosmil"<<centena<<decena<<"y"<<unidad<<endl;}
  
  
   system("PAUSE");	
  return 0;
}

I would change two things. Testing should have a couple other, unrelated things show up later, but this will get you a liitle closer I think.

1) Change the order you check for numbers: test for the higher numbers first, then the lower numbers later. Like this:

if (n < 10000 && n>=2000){...} 
if (n < 2000 && n>=1000){...}
if (n < 1000 && n>=900){...}

2) Don't try to print out the whole number at once. Like this:

if (n < 10000&& n >=2000) { cout << "dosmil"; }
if (n < 2000&& n >=1000) { cout << "mil"; }  
if (n < 1000&& n >=900) { cout << "novecientos"; }

Don't forget to change your checks for the smaller numbers to

if (unidad == 1){  cout << "uno";}

and you will also need to account for 15 (otherwise you will get 10 and 5).

I would change two things. Testing should have a couple other, unrelated things show up later, but this will get you a liitle closer I think.

1) Change the order you check for numbers: test for the higher numbers first, then the lower numbers later. Like this:

if (n < 10000 && n>=2000){...} 
if (n < 2000 && n>=1000){...}
if (n < 1000 && n>=900){...}

2) Don't try to print out the whole number at once. Like this:

if (n < 10000&& n >=2000) { cout << "dosmil"; }
if (n < 2000&& n >=1000) { cout << "mil"; }  
if (n < 1000&& n >=900) { cout << "novecientos"; }

Don't forget to change your checks for the smaller numbers to

if (unidad == 1){  cout << "uno";}

and you will also need to account for 15 (otherwise you will get 10 and 5).

thanks!
:D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.