Question #22770

Write a whole program for presidential Elections, the user will enter his votes based on the code for each candidate. The Program will add the total votes for each candidate and proclaim the winner whoever got the most number of votes. The user will stop in accepting votes if the used entered Letter ‘Q’ to quit. Type ‘V’ to vote and ‘R’ to view the result.

Expert's answer

#include <iostream>

using namespace std;

int main()

{ int voutes[10];

cout<<"how many candidates? please enter number"<<endl;

int n;

cin>>n;

int summ;

int sum[n];

int max=0;

for(int i=1;i<=n;i++)

{

cout << "please enter votes of candidate" <<i<<endl;

for(int j=1;j<=10;j++)

{

& cin>>voutes[j];

& cout<<endl;

& summ=summ+voutes[j];

}

sum[i]=summ;

cout<<"sum of candidats "<<i<<" ="<<sum[i]<<endl;

if(sum[i]>max)

{

& max=sum[i];

& }

sum[i]=0;

}

cout<<"max= "<<max<<endl;

return 0;

}

using namespace std;

int main()

{ int voutes[10];

cout<<"how many candidates? please enter number"<<endl;

int n;

cin>>n;

int summ;

int sum[n];

int max=0;

for(int i=1;i<=n;i++)

{

cout << "please enter votes of candidate" <<i<<endl;

for(int j=1;j<=10;j++)

{

& cin>>voutes[j];

& cout<<endl;

& summ=summ+voutes[j];

}

sum[i]=summ;

cout<<"sum of candidats "<<i<<" ="<<sum[i]<<endl;

if(sum[i]>max)

{

& max=sum[i];

& }

sum[i]=0;

}

cout<<"max= "<<max<<endl;

return 0;

}

## Comments

## Leave a comment