Tuesday, July 28, 2009

C question?

I need help with the following! I did this program but don't know why it isn't working!!?! =S





Of 5 given words, in a 5x3 array, store in each row the values corresponding to it's length, number of vocals, and number of consonants.





#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


#include%26lt;string.h%26gt;





void main()


{


int a[5][3], x,y,c,v,l,z=0;


char p[15];


clrscr();





for(y=0;y%26lt;5;y++)


{


printf("\nEscribe nombre: ");


scanf("%s", p);


l=strlen(p);


a[y][0]=l;


do{


if(p[z]==97||101||105||111||117)


c++;


z++;


}while(z!=l);


a[y][1]=c;


a[y][2]=l-c;


c=0;


z=0;


}





for(y=0;y%26lt;5;y++)


{


for(x=0;x%26lt;3;x++)


printf("%d ",a[y][x]);


printf("\n");


}





getch();


}





Any suggestions why it doesn't work?

C question?
Ive made some changes to your programme:





main()


{


int a[5][3], x,y,c,v,l,z=0;


char p[15];


char cc; /* compare char */





for(y=0;y%26lt;5;y++)


{


printf("\nEscribe nombre: ");


scanf("%s", p);


l=strlen(p);


a[y][0]=l;


a[y][1] = a[y][2] = 0; /* must initialise counters */


for( z = 0; z %26lt; l; z++ ) /* use a for loop here not while */


{


cc = toupper( p[z] ); /* one conversion */


/* your checking was not quite right; I also used 'c' values to make it more readable */


if( cc == 'A' || cc == 'E' || cc == 'I' || cc == 'O' || cc == 'U' )


a[y][1]++; /* increase vowel count *./


else


a[y][2]++; /* increase const count */


}


}





for(y=0;y%26lt;5;y++)


{


for(x=0;x%26lt;3;x++)


printf("%d ",a[y][x]);


printf("\n");


}





getch(); /* best to print out a press return to continue */


}


No comments:

Post a Comment