Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that does the following: Display the table with appropriate labe

ID: 3549558 • Letter: W

Question

Write a program that does the following: Display the table with appropriate labels for the rows and columns. Compute and display the total number of votes received by each candidate and the percentage of the total votes cast. If any one candidate received over 50 percent of the votes, the program should display a message declaring that the candidate the winner.d. If no candidate received 50 percent of the votes, the program should display a message declaring a runoof between the two candidates receiving the highest number of votes; the two candidates should be identified by their letter names. Run the program once with the data shown and once with candidate C receiving only 108 votes in Precinct 4."

Explanation / Answer

please rate - thanks


if you don't normally use getch(); and #include <conio.h> just remove those lines of code

run with 408 for candidate C in precint 4



run with candidate C having 108 votes in precint 4

code with Candidate C having 108 votes in precint 4




#include <stdio.h>
#include <conio.h>
void display(int[][4]);
void line();
void total(int[][4],double[]);
void winner(double[]);
int main()
{int votes[5][4]={192,48,206,37,147,90,312,21,186,12,121,38,114,21,108,39,267,13,382,29};
int i,j;
double pct[4];
display(votes);
total(votes,pct);
winner(pct);
getch();
}
void winner(double pct[])
{int i,max,max2,winner=0;
for(i=0;i<4;i++)
    if(pct[i]>50)
         {printf("The winner is candidate %c ",'A'+i);
         winner=1;
         }
if(winner==0)
       {max=0;
       for(i=1;i<4;i++)
            if(pct[i]>pct[max])
                 max=i;
       max2=0;
       for(i=1;i<4;i++)
            if(i!=max)
                if(pct[i]>pct[max2])
                    max2=i;
       printf("There will be a runoff between candidate %c and Candidate %c ",'A'+max,'A'+max2);
}
}
void total(int votes[][4],double pct[])
{int i,j,tot[4],grandtotal=0;
for(i=0;i<4;i++)
    {tot[i]=0;
    pct[i]=0;
    }
for(i=0;i<4;i++)
    for(j=0;j<5;j++)
        {tot[i]+=votes[j][i];
        grandtotal+=votes[j][i];
        }
for(i=0;i<4;i++)
    pct[i]=tot[i]/(double)grandtotal*100.;
printf("| total |");
for(i=0;i<4;i++)
      printf("     %4d    |",tot[i]);
printf(" ");
line();
printf("| percent |");
for(i=0;i<4;i++)
      printf("     %4.1f    |",pct[i]);
printf(" ");
line();     
}
void display(int votes[][4])
{int i,j;
printf("| Precint | Candidate A | Candidate B |Candidate C | Candidate D | ");
line();
for(i=0;i<5;i++)
   {printf("|    %d    |",i+1);
   for(j=0;j<4;j++)
       printf("      %3d    |",votes[i][j]);
   printf(" ");
   line();
}
  
}
void line()
{int i;
for(i=0;i<66;i++)
     printf("-");
printf(" ");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote