how to count votes in the following code

July 30, 2016 at 01:44:49
Specs: Windows 7
#include<iostream>
#include<stdlib.h>
using namespace std;

class election
{
public :
int a,age;
char name[10];

public :
void get();
void getdata();
/* void sort (int n)*/
void display();
};


void election :: get()
{


cout<<"enter your name \t";
cin>>name;
cout<<"enter your age\t\t";
cin>>age;
/* if(age<18)
{
cout<<"you are not eligible for voting\n";


}*/
}

void election :: getdata()
{

cout<<"\n who you want to vote \n 1: BJP \n 2: CONGRESS \n 3:SHIVSENA \n 4: MNS \n 5:RASHTRAVADI \n cast your vote\t";
cin>>a;
cout<<"thanks for voting";

}

void election :: display()
{


cout<<"\n name : \t"<<name;
cout<<"\nage : \t\t"<<age;
cout<<"\nvote : \t\t"<<a;
}

int main()
{
int b;
char h,p;
do
{

election s;
cout<<"\n\n\nFILL YOUR DATA\n";
s.get();

cout<<"\n PRESS 1 TO VOTE \n PRESS 2 IF YOU DONT WANT TO VOTE \n 1: VOTE \n 2: EXIT \n";
cin>>b;
switch(b)
{

case 1:
do
{
if(s.age<18)
{
cout<<"you are not eligible to vote";
break;
}
cout<<"CAST YOUR VOTE\n";

s.getdata();

cout<<"\nCHECK YOU HAVE VOTED THE SAME\n";
s.display();

cout<<"\ncheck if its your data ?\n if no press 'n'\n if yes press 'y'";
cin>>p;
}while(p=='n');
break;
case 2:

exit(0);
break;
default:
cout<<"invalid choice";
}
cout<<"\n new member press y to vote(y/n)";
cin>>h;
}while(h=='y');

}


See More: how to count votes in the following code

Reply ↓  Report •


#1
July 30, 2016 at 12:40:35
There is always just 1 vote.

Reply ↓  Report •

#2
July 31, 2016 at 01:45:46
How can I count votes of each candidate and declare highest one as winner

Reply ↓  Report •

#3
July 31, 2016 at 09:35:20
Before you can count the votes you have to record them.

Enough hints - this is obviously a homework question.


Reply ↓  Report •

Related Solutions

#4
August 1, 2016 at 19:43:28
no thats not a homework question . i m practicing c++. .how to record the votes .using a array or different variables for each candidate.

Reply ↓  Report •


Ask Question