1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

real number to dollars

Discussion in 'C' started by stigmatas, Nov 29, 2011.

  1. stigmatas

    stigmatas New Member

    Joined:
    Nov 22, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I new to comvert a real number to dollars.. i got this but, when i enter a number of four digits it doesn't work.. any improvement will be welcome.. thanks!

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
    
    printf("\n Sistema de Conversi%cn a Dolares", 162);
        printf("\n -------------------------------");               
        printf("\n\n Entre un n%cmero real: ", 163);
        scanf("%lf", &numero_real_1); 
    
    numero_entrado =  numero_real_1;            //Guarda el numero_entrado.       
           num_temp = (int)numero_real_1;
           centavos = numero_real_1 - num_temp;              
           centavos = centavos * 100;               
           centavos_entrados = (int)centavos;          //Guarda los centavos         
                                                       //entrados.
           for(n= 0; n <  numero_real_1; n++)
           {   
               if(n == 3)
               {
                  numero_real_1 = numero_real_1/1000;     //12.345
                  num_temp = (int) numero_real_1;         //12
                  centavos =  numero_real_1 - num_temp;   //0.345
                  centavos = centavos * 1000;             //345.
                  cien = (int)centavos;                   //345
                  //printf("\n Cien: %d\n\n", cien);
               } 
               if(n == 6)
               {  
                  numero_real_1=  numero_real_1/1000;     //4.587261
                  num_temp = (int) numero_real_1;         //4
                  centavos =  numero_real_1 - num_temp;   //0.587
                  centavos = centavos * 1000;             //587.
                  mil = (int)centavos;                    //587
                  //printf(" Mil: %d\n\n", mil);
               }
               if(n == 9)
               {  
                  numero_real_1 = numero_real_1/1000;            
                  num_temp = (int) numero_real_1;           
                  centavos =  numero_real_1 - num_temp;     
                  centavos = centavos * 1000;        
                  millon = (int)centavos;               
                  //printf(" Millon: %d\n\n", millon);
               }         
           }
           n--;
           //printf(" N: %d", n);
           //printf("\n\n Num_temp: %d", num_temp);
    	   printf("\n\n\n\n La divisi%cn de los n%cmeros es: %lf", 162, 163, divisor);
           printf("\n\n\n El n%cmero entrado es: %lf\n", 163, numero_entrado);
           
           if(n == 3)
           {
              printf("\n\n El n%cmero en formato de d%clares es: $%d.%.2d", 
                     163, 162, cien, centavos_entrados);
           }
           
           if(n == 4)
           {
              //printf(" N: %d", n);
              printf("\n\n El n%cmero en formato de d%clares es: $%d,%.2d.%.d", 
                     163, 162, mil, cien, centavos_entrados);
           }
           
           if(n == 6)
           {
              printf("\n\n El n%cmero en formato de d%clares es: $%d,%.3d.%.2d", 
                     163, 162, mil, cien, centavos_entrados);
           }
           
           if(n == 7)
           {
              printf("\n\n El n%cmero en formato de d%clares es: $%d,%d,%.3d.%.2d", 
              163, 162, num_temp, mil, cien, centavos_entrados);
           }
             
           if(n == 9)
           {
              printf("\n\n El n%cmero en formato de d%clares es: $%d,%.3d,%.3d.%.2d", 
                     163, 162, millon, mil, cien, centavos_entrados);
           }
           printf("\n\n\n ");
           system("pause");
           return 0;
    }
     
  2. jose_peeterson

    jose_peeterson New Member

    Joined:
    May 19, 2011
    Messages:
    56
    Likes Received:
    1
    Trophy Points:
    0
    can you please translate your comments to english
    thanks
     

Share This Page