#include <stdio.h>
#include <float.h> //-FLT_MAX et FLT_MAX
void afficher(char poste[], float age[], float nbCafe[],
int nbPers, char quand_tri[])
{
int i;
printf("Contenu des 3 tableaux %s le tri \n ",
quand_tri);
printf("Indice age nbCafe poste \n");
for(i = 0 ; i < nbPers; i++)
{
printf("%3d) %8.2f %9.1f ", i , age[i] ,nbCafe[i]);
switch(poste[i])
{
case 'A': printf("analyste");break;
case 'P' : printf("Programmeur");break;
case 'O': printf("operateur ");break;
case 'S': printf("autre");break;
}
printf("\n");
}
}
It is at this part that I can’t found how to write a code in a good way using (function return) to have an "int" of how many analysts there are.
int Numanalystes(char tableau[], int nbElem)
{
int i;
int alystesN = 0;
for(i=0; i<nbElem; i++)
if (tableau[i]="analyste" )
alystesN = alystesN+1;
return alystesN;
}
int main()
{
char poste[] = {'P', 'P', 'O', 'A', 'P', 'A', 'P', 'P'};
//marie celi ...
float age[] = {25, 19, 27, 30, 65, 24, 56, 29},
nbCafe[] = {3, 1, 5, 0, 3, 4, 0, 3};
int nbPers = sizeof(poste) / sizeof(char);
// Table
afficher (poste,age,nbCafe,nbPers,"avant");
// How many analyste
//How many Programmeur
//How many operateur
return 0 ;
}
I have a problem on function return. I want to find in my execution how many analysts there are, how many programmers there are and, how many operators there are.
For example:
Exécution :
Contenu des 3 tableaux avant le tri
Indice age nbCafe poste
0) 25.00 3.0 Programmeur
1) 19.00 1.0 Programmeur
2) 27.00 5.0 operateur
3) 30.00 0.0 analyste
4) 65.00 3.0 Programmeur
5) 24.00 4.0 analyste
6) 56.00 0.0 Programmeur
7) 29.00 3.0 Programmeur
how many Programmeurs :5
how many analystes : 2
how many operateurs : 1
>Solution :
you mean
if (tableau[i]=='A' )
since tableau is an array of single characters
also you need ‘==’ to compare things
so like this
int Numanalystes(char tableau[], int nbElem)
{
int alystesN = 0;
for(int i=0; i<nbElem; i++){
if (tableau[i]=='A'){
alystesN++;
}
}
return alystesN;
}