/* Example: Vowel Counting Goal: Multiple selection Author: Peter Brusilovsky */ #include void main() { char c; int a, e, i, o, u, others; int pa, pe, pi, po, pu, pothers; float total; a = e = i = o = u = others = 0; /* Accumulating counters in the loop */ while ((c = getchar()) != EOF) switch (c) { case 'e': e++; break; case 'i': i++; break; case 'u': u++; break; case 'o': o++; break; case 'a': a++; break; default: others++; break; } /* Calculating percentages */ total = a + e + i + o + u + others; pa = (a / total) * 100; pe = (e / total) * 100; pi = (i / total) * 100; po = (o / total) * 100; pu = (u / total) * 100; pothers = (others / total) * 100; /* Printing results */ printf("\nNumbers of characters:\n\n"); printf("a %d; e %d; i %d; o %d; u %d; rest %d\n", a, e, i, o, u, others); printf("\nPercentages:\n\n"); printf("a %d%%; e %d%%; i %d%%; o %d%%; u %d%%; rest %d%%\n", pa, pe, pi, po, pu, pothers); }