Aide a fusionner des fonction

Fermé
tenohthree Messages postés 50 Date d'inscription dimanche 1 novembre 2009 Statut Membre Dernière intervention 1 janvier 2010 - 1 janv. 2010 à 11:11
tenohthree Messages postés 50 Date d'inscription dimanche 1 novembre 2009 Statut Membre Dernière intervention 1 janvier 2010 - 1 janv. 2010 à 14:27
Bonjour,
j'aimerai bien que vous m'aidez à fusionner mon mini projet car je suis nulle dans le les fonctions

voila le premier code :

#include<stdio.h>
#include<string.h>
#include<conio.h>
 
 int main(void)
{
char l1[50],l2[50],l3[50],l4[50], lettre[256];
char *espace = " ",choix = 'o';
char unite[25][25]={"end","un","deux","trois","quatre", "cinq", "six", "sept", "huit","neuf","dix","onze","douze","treize","quatorze","quinze","seize","dix-sept","dix-huit","dix-neuf"};
char dizaine[25][25]={"","","vingt","trente","quarante","cinquante","soixante","","quatre-vingt",""};
char centaine[3][6]={"end","cent","cents"};
int s,i,x1,x2,x3,x4;
strcpy(lettre,"");
while((choix=='o')||(choix=='O'))
 {
printf("donner une chiffre literalement\n");
scanf("%s",&l1);
scanf("%s",&l2);
scanf("%s",&l3);
scanf("%s",&l4);
 
strcat(lettre,l1);
strcat(lettre,espace);
strcat(lettre,l2);
strcat(lettre,espace);
strcat(lettre,l3);
strcat(lettre,espace);
strcat(lettre,l4);
 
printf("%s\n",lettre);
 
for(i=0;i<25 || (strcmp(l1,unite[i])==0) ;i++)
if (strcmp(l1,unite[i])==0)
x1=i;
 
for(i=0;i<25 || (strcmp(l2,centaine[i])==0) ;i++)
if (strcmp(l2,centaine[i])==0)
x2=100;
 
for(i=0;i<25 || (strcmp(l3,dizaine[i])==0) ;i++)
if (strcmp(l3,dizaine[i])==0)
x3=10*i;
 
for(i=0;i<30 || (strcmp(l4,unite[i])==0) ;i++)
if (strcmp(l4,unite[i])==0)
x4=i;
 
printf(" ca fait :%d  ",x1*x2+x3+x4);
printf("\nEncore d'autre? (O/N): ");
 choix = getche();
 printf("\n===================================================\n");
}//nendwhile
getch();
return 0;
}


et le 2eme
#include<stdio.h>
#include<string.h>
#include<conio.h>
 
 void ChiffreEnLettre(int, char*);
int main()
 {
 int chiffre = 0;
 char choix = 'o',lettre[256];
 while((choix=='o')||(choix=='O'))
 {
 printf("Introduire un chiffre entier : ");
 scanf("%d", &chiffre);
 ChiffreEnLettre(chiffre,lettre);
 printf("\nEn lettre ca fait %s: ", lettre);
 
 printf("\nEncore d'autre? (O/N): ");
 choix = getche();
 printf("\n===================================================\n");
 }
 return 0;
 }
 
 
 
void ChiffreEnLettre(int chiffre , char lettre[256])
 {
 int centaine, dizaine, unite, reste, y,i;
 
		      
 reste = chiffre;
 strcpy(lettre, "");
 
 
 for(i=1000000000; i>=1; i/=1000)
 {
 //printf("rest:%d,chiffre:%d",reste,chiffre);
 y = reste/i;
 /*printf("%d",reste);
 printf("%d",chiffre);
 printf("%d",y);
 printf("%d",i);*/
 if(y!=0)
 {
 centaine = y/100;
 dizaine = (y - centaine*100)/10;
 unite = y-(centaine*100)-(dizaine*10);
 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:
 if(unite==0) strcat(lettre,"dix");
 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:
 if(unite==0)strcat (lettre,"soixante-dix ");
 else strcat (lettre,"soixante ");
 
 break;
 case 8:
 strcat(lettre,"quatre-vingt ");
 break;
 case 9:
  if(unite==0)strcat(lettre,"quatre-vingt-dix ");
  else strcat(lettre,"quatre-vingt ");
 } // endSwitch(dizaine)
 
 switch(unite)
 {
 case 0:
 break;
 case 1:
 if(dizaine == 1 || dizaine == 7 || dizaine == 9 ) strcat(lettre,"onze ");
 else strcat(lettre,"un ");
 break;
 case 2:
 if(dizaine == 1 || dizaine == 7 || dizaine == 9 ) strcat(lettre,"douze ");
 else strcat(lettre,"deux ");
 break;
 case 3:
 if(dizaine == 1 || dizaine == 7 || dizaine == 9 ) strcat(lettre,"treize ");
 else strcat(lettre,"trois ");
 break;
 case 4:
 if(dizaine == 1 || dizaine == 7 || dizaine == 9 ) strcat(lettre,"quatorze ");
 else strcat(lettre,"quatre ");
 break;
 case 5:
 if(dizaine == 1 || dizaine == 7 || dizaine == 9 ) strcat(lettre,"quinze ");
 else strcat(lettre,"cinq ");
 break;
 case 6:
 if(dizaine == 1 || dizaine == 7 || dizaine == 9 ) strcat(lettre,"seize ");
 else strcat(lettre,"six ");
 break;
 case 7:
 if(dizaine == 1 || dizaine == 7 || dizaine == 9 ) strcat(lettre,"dix-sept ");
 else strcat(lettre,"sept ");
 break;
 case 8:
 if(dizaine == 1 || dizaine == 7 || dizaine == 9 ) strcat(lettre,"dix-huit ");
 else strcat(lettre,"huit ");
 break;
 case 9:
 if(dizaine == 1 || dizaine == 7 || dizaine == 9 ) 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;
 } // end for
 if(strlen(lettre)==0) strcpy(lettre,"zero");
 
 }

il vaudra mieux qu'on fait un "main" qui fait le choix 1 ou 2 pour appeler le programme 1 ou 2

Merci d'avance
A voir également:

1 réponse

tenohthree Messages postés 50 Date d'inscription dimanche 1 novembre 2009 Statut Membre Dernière intervention 1 janvier 2010
1 janv. 2010 à 14:27
comment?
0