Yesterday, I posted a similar problem (involving numbers) which was solved by Clinton Portis (Thanks by the way) which involved several if statements. This time I got one with a string :rolleyes:
If there's some kind of space saving technique please let me know :mrgreen:
#include <stdio.h>
#define SIZE 5
int main(void)
{
char ch, array[SIZE] = {0};
int a = 0, e = 1, i = 2, o = 3, u = 4;
int cnt = 0;
while ((ch = getchar()) != NULL && ch != '\n')
{
if (ch == 'a')
++array[0];
if (ch == 'e')
++array[1];
if (ch == 'i')
++array[2];
if (ch == 'o')
++array[3];
if (ch == 'u')
++array[4];
cnt++;
}
printf("You entered %d letters\n", cnt);
printf("Number of 'a': %d & Percent of Total: %.2f\n", array[0], (float) array[0]/cnt*100);
printf("Number of 'e': %d & Percent of Total: %.2f\n", array[1], (float) array[1]/cnt*100);
printf("Number of 'i': %d & Percent of Total: %.2f\n", array[2], (float) array[2]/cnt*100);
printf("Number of 'o': %d & Percent of Total: %.2f\n", array[3], (float) array[3]/cnt*100);
printf("Number of 'u': %d & Percent of Total: %.2f\n", array[4], (float) array[4]/cnt*100);
return 0;
}