1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
void header()
{
cout<<"\t\t--presidential election program -- "<<endl<<endl;
}
int inservote (int number, int pres1, int pres2,int inval)
{
if (number==1)
{
pres1+=1;
return pres1;
}
else if (number==2)
{
pres2+=1;
return pres2;
}
else
{
inval+=1;
return 0;
}
}
void winBoard(int pres1,int pres2,int amount,int inval)
{
if (pres1>pres2)
{
cout<<"congratulation president 1 win by "<<pres1<<" vote."<<endl;
}
else if (pres2>pres1)
{
cout<<"congratulation president 2 win by "<<pres2<<" suara."<<endl;
}
else
{
cout<<"draw"<<endl;
}
cout<<endl;
cout<<" total "<<amount<<" chooser."<<endl;
cout<<"president 1 by : "<<pres1<<" vote."<<endl;
cout<<"president 2 by : "<<pres2<<" vote."<<endl;
cout<<"invalid : "<<inval<<" vote."<<endl;
cout<<endl;
cout<<endl;
cout<<"selection complete "<<endl;
}
int main()
{
header();
int amount_chooser ,counter = 0,choice, president1=0,president2=0,invalid=0;
cout<<"input the amount chooser : "<<endl;
cin>>amount_chooser;
system("CLS");
while (counter < amount_chooser)
{
header();
cout<<"selecktor to: "<<counter+1<<" of "<<amount_chooser<<" chooser."<<endl;
cout<<endl;
cout<<"press 1 for president 1 or press 2 for president 2 : "<<endl;
cin>>choice;
if (choice==1)
president1=inservote(choice,president1,president2,invalid);
else if (choice==2)
president2=inservote(choice,president1,president2,invalid);
else
invalid=inservote(choice,president1,president2,invalid);
counter++;
system("CLS");
}
header();
cout<<endl;
winBoard(president1,president2,amount_chooser,invalid);
getch();
return 0;
}
|