0
I want the program like this. There are three persons A, B and C. They are participated in elections.
six people go to elect them.. and finally the person who won in election should be displayed.. I want this idea in c++ program.. somebody help? please..
4 Antworten
+ 3
#include <iostream>
using namespace std;
int main() {
char x;
int votes_A = 0;
int votes_B = 0;
int votes_C =0;
for(int i=1;i<7;i++)
{
cout<<"Enter A to vote for candidate A\nEnter B to vote for candidate B\nEnter C to vote for candidate C\n" ;
cin>>x;
if(x=='A'|| x=='a')
votes_A ++;
else if(x=='B'|| x=='b')
votes_B ++;
else
votes_C ++;
}
if(votes_A != votes_B || votes_B != votes_C || votes_A != votes_C )
{
if(votes_A > votes_B && votes_A > votes_C)
cout<<"candidate A has won the election by "<<votes_A <<" votes\n";
else if(votes_B > votes_A && votes_B > votes_C )
cout<<"candidate B has won the election by "<<votes_B <<" votes\n";
else if(votes_C > votes_A && votes_C > votes_B )
cout<<"candidate C has won the election by "<<votes_C <<" votes\n";
}
else
cout<<"None of the candidates have won the election \n";
return 0;
}
+ 4
int votesA = 0, votesB = 0, votesC = 0;
int person, vote;
for (person = 0; person < 6; person++) {
cout<<"Enter 1,2,3 to vote for A,B,C : ";
cin>>vote;
switch (vote) {
case 1:votesA++;break;
case 2:votesB++;break;
case 3:votesC++;break;
}
}
// Find the largest of votesA, votesB, votesC and declare A or B or C as winner accordingly.
+ 2
the above code is compatible for each situation.
0
thank you very much sir...