Write a program that perform a survey tally on beverages The

Write a program that perform a survey tally on beverages. The program should prompt for the next person until a sentinel value of -1 is entered to terminate the program. Each person participating in the survey should choose their favorite average from the following list: Coffee tea coke Orange juice

Solution

#include<stdio.h>
int main()
{
   int nChoice=0,nPersons=0,nCoffee=0,nTea=0,nCock=0,nJuice=0;

   printf(\"1.Coffee\ 2.Tea\ 3.cock\ 4.OrangeJuice\ \");
  
   //to run untill person press -1
   do
   {
   nPersons++;
       printf(\"Please input the favorite beverage of person #%d\ \",nPersons);
       printf(\"Choose 1,2,3 or 4 from the above menu or -1 to exit the program\ \ \");
       scanf(\"%d\",&nChoice);
       //choose Choice
       if(nChoice == 1)
           nCoffee++;
       else if(nChoice == 2)
           nTea++;
       else if(nChoice == 3)
           nCock++;
       else if(nChoice == 4)
           nJuice++;
   }while(nChoice != -1);
   printf(\"Total number of people survayedis %d .The results are as fallows \",nPersons-1);
   printf(\"Beverage               Number of votes\ \");
   printf(\"******************************************\ \");
   printf(\"Coffee               %d\ \",nCoffee);
   printf(\"Tea                 %d\ \",nTea);
   printf(\"Cock                 %d\ \",nCock);
   printf(\"OrangeJuice %d\ \",nJuice);
}

The out put will display as above.

Important functionality

------------------------------------

1.printf,scanf are predefined functions in C ,these function definations are available in stdio.h sowe need to include them

2.printf is used to display a string on Output screan and scanf is used to take data from Output screen.

3.If,elseif are control statements, If given statement is true then the line below the if condition will executed other wise controller will check the else if condition

4.while loop is to execute the statements repeated number of times untill the condition in while loop get failed.

5.%d is used to display or get integer data,\ is used to display a newline on Output screen

 Write a program that perform a survey tally on beverages. The program should prompt for the next person until a sentinel value of -1 is entered to terminate th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site