Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When I compile the code below, the Total Votes/Percents are drawn from the row totals and not the column totals. How can I fix this?

When I compile the code below, the Total Votes/Percents are drawn from the row totals and not the column totals. How can I fix this? #include  int main() { int votes[5][4]={ 192,48,206,37, 147,90,312,21, 186,12,121,38, 114,21,408,39, 267,13,382,29}; char cand[4]={'A','B','C','D'}; int row_totals[5]; int col_totals[4]; int total_votes; float percent[4]; int row,col; int total=0; for(row=0;row<=4;row++) { row_totals[row]=0; for(col=0;col<=3;col++) { row_totals[row] += votes[row][col]; total+=votes[row][col]; } } printf(" Candidate Candidate Candidate Candidate Total Percent "); printf(" Precinct A B C D "); for(row=0;row<=4;row++) { printf("%6d",row+1); for(col=0;col<=3;col++) { printf("%12d",votes[row][col]); } printf("%11d",row_totals[row]); percent[row]=(double)(row_totals[row]*100)/total; printf("\t%.2f ",percent[row]); } int i; double first=percent[0]; double sec=percent[0]; int maxVal,second_big; for(i=0;i<4;i++) { if(first>percent[i]) { first=percent[i]; maxVal=i; } } int j; for(j=0;j<4;j++) { if(percent[j]>sec && percent[j]!=sec) { sec=percent[j]; second_big=j; } } if(first>50) { printf("%d is the winner. ",cand[maxVal]); } else if(sec<=50) { printf("%c and %c are in a runoff. ",cand[maxVal],cand[second_big]); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions