Skip to content

Instantly share code, notes, and snippets.

@bitwiser
Last active August 29, 2015 13:56
Show Gist options
  • Save bitwiser/9188902 to your computer and use it in GitHub Desktop.
Save bitwiser/9188902 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main ()
{
int num, redctr, bluectr, brownctr, yellowctr, greenctr, purplectr;
redctr = 0, bluectr = 0, brownctr = 0, yellowctr = 0, greenctr = 0, purplectr = 0;
printf("The Many Colors of M&M's Candy\n\n");
printf("1. red\n");
printf("2. blue\n");
printf("3. brown\n");
printf("4. yellow\n");
printf("5. green\n");
printf("6. purple\n");
printf("\nVote on your favoriate color by pressing the number before it.\n\n");
printf("(Press 9 to stop voting.)\n\n");
input:
printf("Enter a vote:\n\n");
while(scanf("%d", &num) && num!=9){
switch (num)
{
case 1:
printf ("\nYou voted for red.\n");
redctr = redctr + 1;
break;
case 2:
printf ("\nYou voted for blue.\n");
bluectr = bluectr + 1;
break;
case 3:
printf ("\nYou voted for brown.\n");
brownctr = brownctr + 1;
break;
case 4:
printf ("\nYou voted for yellow.\n");
yellowctr = yellowctr + 1;
break;
case 5:
printf ("\nYou voted for green.\n");
greenctr = greenctr + 1;
break;
case 6:
printf ("\nYou voted for purple\n");
purplectr = purplectr + 1;
break;
default:
printf ("\nYou have entered and invalid vote. Please try again.\n");
break;
}
}
printf("Voting Count: \n");
printf("1. red %i\n", redctr);
printf("2. blue %i\n", bluectr);
printf("3. brown %i\n", brownctr);
printf("4. yellow %i\n", yellowctr);
printf("5. green %i\n", greenctr);
printf("6. purple %i\n", purplectr);
printf("\n\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment