1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
| #include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
/*
La valeur de chiffre ne doit pas dépasser la plage de valeur
pour unsigned int càd 4 294 967 295 , sinon il y a erreur de
conversion !!!
*/
void ChiffreEnLettre(unsigned int, char*);
int main()
{
unsigned int x = 0;
char choix = 'o',c[256];
while((choix=='o')||(choix=='O'))
{
cout << "Introduire un chiffre entier : ";
cin >> x;
ChiffreEnLettre(x,c);
cout << "\nEn lettre ca fait : "<< c <<endl;
cout << "\nEncore d'autre? (O/N): ";
choix = getche();
cout << "\n==================================================="<<endl;
}
return 0;
}
void ChiffreEnLettre(unsigned int chiffre, char * lettre)
{
unsigned int centaine, dizaine, unite, reste, y;
bool dix = false;
strcpy(lettre, "");
reste = chiffre;
for(int i=1000000000; i>=1; i/=1000)
{
y = reste/i;
cout << y << endl;
if(y!=0)
{
centaine = y/100;
cout << centaine << endl;
dizaine = (y - centaine*100)/10;
cout << dizaine << endl;
unite = y-(centaine*100)-(dizaine*10);
cout << unite << endl;
switch(centaine)
{
case 0:
break;
case 1:
strcat(lettre,"cent ");
break;
case 2:
if((dizaine == 0)&&(unite == 0)) strcat(lettre,"deux cents ");
else strcat(lettre,"deux cent ");
break;
case 3:
if((dizaine == 0)&&(unite == 0)) strcat(lettre,"trois cents ");
else strcat(lettre,"trois cent ");
break;
case 4:
if((dizaine == 0)&&(unite == 0)) strcat(lettre,"quatre cents ");
else strcat(lettre,"quatre cent ");
break;
case 5:
if((dizaine == 0)&&(unite == 0)) strcat(lettre,"cinq cents ");
else strcat(lettre,"cinq cent ");
break;
case 6:
if((dizaine == 0)&&(unite == 0)) strcat(lettre,"six cents ");
else strcat(lettre,"six cent ");
break;
case 7:
if((dizaine == 0)&&(unite == 0)) strcat(lettre,"sept cents ");
else strcat(lettre,"sept cent ");
break;
case 8:
if((dizaine == 0)&&(unite == 0)) strcat(lettre,"huit cents ");
else strcat(lettre,"huit cent ");
break;
case 9:
if((dizaine == 0)&&(unite == 0)) strcat(lettre,"neuf cents ");
else strcat(lettre,"neuf cent ");
}// endSwitch(centaine)
switch(dizaine)
{
case 0:
break;
case 1:
dix = true;
break;
case 2:
strcat(lettre,"vingt ");
break;
case 3:
strcat(lettre,"trente ");
break;
case 4:
strcat(lettre,"quarante ");
break;
case 5:
strcat(lettre,"cinquante ");
break;
case 6:
strcat(lettre,"soixante ");
break;
case 7:
dix = true;
strcat(lettre,"soixante ");
break;
case 8:
strcat(lettre,"quatre-vingt ");
break;
case 9:
dix = true;
strcat(lettre,"quatre-vingt ");
} // endSwitch(dizaine)
switch(unite)
{
case 0:
if(dix) strcat(lettre,"dix ");
break;
case 1:
if(dix) strcat(lettre,"onze ");
else strcat(lettre,"un ");
break;
case 2:
if(dix) strcat(lettre,"douze ");
else strcat(lettre,"deux ");
break;
case 3:
if(dix) strcat(lettre,"treize ");
else strcat(lettre,"trois ");
break;
case 4:
if(dix) strcat(lettre,"quatorze ");
else strcat(lettre,"quatre ");
break;
case 5:
if(dix) strcat(lettre,"quinze ");
else strcat(lettre,"cinq ");
break;
case 6:
if(dix) strcat(lettre,"seize ");
else strcat(lettre,"six ");
break;
case 7:
if(dix) strcat(lettre,"dix-sept ");
else strcat(lettre,"sept ");
break;
case 8:
if(dix) strcat(lettre,"dix-huit ");
else strcat(lettre,"huit ");
break;
case 9:
if(dix) strcat(lettre,"dix-neuf ");
else strcat(lettre,"neuf ");
} // endSwitch(unite)
switch (i)
{
case 1000000000:
if(y>1) strcat(lettre,"milliards ");
else strcat(lettre,"milliard ");
break;
case 1000000:
if(y>1) strcat(lettre,"millions ");
else strcat(lettre,"million ");
break;
case 1000:
strcat(lettre,"mille ");
}
} // end if(y!=0)
reste -= y*i;
dix = false;
} // end for
if(strlen(lettre)==0) strcpy(lettre,"zero");
} |
Partager