Question

In: Computer Science

In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of votes obtained...

In a C language program CODE BLOCKS !!!!!!!!

Program that stores the number of votes obtained by 3 amounts in five different zones. Is required:
+ Request the total of votes by zone of each candidate, the values must be entered on the keyboard and validate that it does not accept negative numbers
+ Menu that requests the operation to be performed, in case of entering an invalid data send an error message and request the operation again
+ Option to perform another calculation

Note: The code must perform the calculations throughout the array, operations are not accepted assuming different values to the elements of the array

What will be told in the program:
* The area that obtained the most votes
* Total votes for each candidate
* The candidate with the fewest votes
* The number of votes obtained by zones
*Option menu
* Validate Negative data
* Request if you want to make another calculation

Solutions

Expert Solution

code:

#include<stdio.h>
#include<conio.h>

// Declaring a function which takes input
void read_input(int a[],int x);

// Declaration of arrays which stores votes
int p1[5],p2[5],p3[5],total[5];
void main()
{
   //Declaration of necessary variables
   int i,choose,cal,p1_total=0,p2_total=0,p3_total=0;
  

   // calling read_input function which reads input from the user
   read_input(p1,1);
   read_input(p2,2);
   read_input(p3,3);
      
   // Calculating total votes in each Zone
   for(i=0;i<5;i++)
   {
       total[i] = p1[i]+p2[i]+p3[i];
   }
      
   // Calculating each person Total votes
   for(i=0;i<5;i++)
   {
       p1_total = p1_total+p1[i];
       p2_total = p2_total+p2[i];
       p3_total = p3_total+p3[i];
   }
  
   // Taking do while loop to iterate the menu until user exits
   do
   {
      
       printf("\n*********MENU********\n");
       printf("1.The area that obtained the most votes\n");
       printf("2.Total votes for each candidate\n");
       printf("3.The candidate with the fewest votes\n");
       printf("4.The number of votes obtained by zones\n");
       scanf("%d",&choose);
      
       // Calculating which area has most votes
       if(choose==1)
       {
           int max = total[0],area;
          
           for(i=1;i<5;i++)
           {
               if(total[i]>max)
               {
                   max = total[i];
                   area = i;
               }
           }
          
           printf("Area %d has obtained most votes with %d votes\n",area+1,max);
       }
      
       // Displaying each person votes
       else if(choose==2)
       {
           printf("Person1 total votes are: %d\n",p1_total);
           printf("Person2 total votes are: %d\n",p2_total);
           printf("Person3 total votes are: %d\n",p3_total);
       }
      
       // Finding the person who got fewest votes
       else if(choose==3)
       {
           int per,min;
          
           if ((p1_total < p2_total) && (p1_total < p3_total))
           {
               min = p1_total;
               per = 1;
           }
          
           else if((p2_total < p1_total) && (p2_total < p3_total))
           {
               min = p2_total;
               per = 2;
           }
           else
           {
               min = p3_total;
               per = 3;
           }
          
           printf("Person %d has got fewest votes with %d votes\n",per,min);
       }
      
       // Displaying number of votes in each zone
       else if(choose==4)
       {
           for(i=0;i<5;i++)
           {
               printf("Number of votes in Zone %d are: %d\n",i+1,total[i]);
           }
       }
      
       printf("\nDo you want to perform another calculation?\n1.Yes\t2.No: ");
       scanf("%d",&cal);
   }while(cal==1);
  
   printf("GoodBye!!!\n");
  
  
  

}

// Function definition which reads input
void read_input(int a[],int x)
{
   int n=0;
   do
   {
       while(n<5)
       {
           printf("Enter person %d votes in zone %d: ",x,n+1);
           scanf("%d",&a[n]);
          
           //Negative number validation
           if(a[n]<0)
           {
               printf("Please enter a positive number\n");
               break;
           }
          
           else
           {
               n++;
           }
       }
   }while(n<5);
   printf("\n");
  
}

OUTPUT


Related Solutions

In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of computers sold...
In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of computers sold by three vendors in four different zones. Is required:  Request the sale amount of each seller by zone, the values must be entered through the keyboard and validate that it does not accept negative numbers.  Menu that requests the operation to be carried out. In case of entering an invalid data, send an error message and request the operation again.  Option...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
Please code in C language. Server program: The server program provides a search to check for...
Please code in C language. Server program: The server program provides a search to check for a specific value in an integer array. The client writes a struct containing 3 elements: an integer value to search for, the size of an integer array which is 10 or less, and an integer array to the server through a FIFO. The server reads the struct from the FIFO and checks the array for the search value. If the search value appears in...
Code in C-language programming description about convert binary number to decimal number.
Code in C-language programming description about convert binary number to decimal number.
C LANGUAGE ONLY Write a C program to count the total number of duplicate elements in...
C LANGUAGE ONLY Write a C program to count the total number of duplicate elements in an array. Enter the number of elements to be stored in the array: 3 Input 3 elements in the arrangement: element [0]: 5 element [1]: 1 element [2]: 1 Expected output: The total number of duplicate elements found in the array is: 1
Using C++, write a code that this program always stores text file output into a text...
Using C++, write a code that this program always stores text file output into a text file named "clean.txt". -The program should read one character at a time from "someNumbers.txt", and do the following. -If it is a letter, print that letter to the screen, AND also store it in the text file. All letters should be converted to lowercase beforehand. -If it is a number, print that number to screen, but do NOT store it in the text file....
Write a C program (using Code::blocks) that outputs a formatted header line and creates 10 children...
Write a C program (using Code::blocks) that outputs a formatted header line and creates 10 children processes each of which displays a line of the output as shown below. Notice the values of Child no and x, they have to be the same as shown here while the processes PIDs values are based on the what your system assigns to these processes. Child    PID        PPID      X 0           13654    13653    5 1           13655    13653    10 2           13656    13653    15 3           13657   ...
Write a program in C language that uses a binary search algorithm to guess a number...
Write a program in C language that uses a binary search algorithm to guess a number from 1 to 100. The computer will keep guessing until they get the users number correct.
c++ is the language Code an O(nlog(n)) algorithm to count the number of inversions DO NOT...
c++ is the language Code an O(nlog(n)) algorithm to count the number of inversions DO NOT ADD OR EDIT FUNCTIONS USE THESE ONLY DO NOT EDIT THE TEST FILE EITHER countInv.cpp #include <vector> #include <algorithm> using namespace std; int mergeInv(vector<int>& nums, vector<int>& left, vector<int>& right) { // You will need this helper function that calculates the inversion while merging // Your code here } int countInv(vector<int>&nums) { // Your code here } countInv_test.cpp #include <iostream> #include <vector> using namespace std;...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++. #include void main() { // Use registers for these in your x86 assembly language program // Only use the .data segment for string (character array) variables int eax; int esi; int ecx; int edi; // Loop the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT