84 529
Assignments Done
99,1%
Successfully Done
In March 2020

# Answer to Question #47544 in C for eridan

Question #47544
Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election.
1
2014-10-08T01:09:04-0400
//answer on Question #47544, Programming, C
#include <stdio.h>
int main(void)
{
printf("Enter the last names of five candidates in a local election and the number of votes received by each candidate\n");
int i=0;
char* name[5][100];
for( i=0; i<5; ++i )
{
printf( "%d. Last name: ", i+1 );
scanf( "%s", name[i] );
}
float sum = 0;
for( i=0; i<5; ++i )
{
}
//calculate result percent for each candidate
float percentage[5];
for( i=0; i<5; ++i )
{
}
//show info
for( i=0; i<5; ++i )
{
}
int curWinner=0;
float curValue = 0;
//winner of elections
for( i=0; i < 5; ++i )
{
if( percentage[i] > curValue )
{
curValue = percentage[i];
curWinner = i;
}
}
printf( "Winner: %s\n", name[curWinner] );
return 0;
}
﻿

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!