In: Computer Science
//Write in C++
//use this evote code and add File I/O operations (as specified in the comments) to it.
#include<iostream>
using namespace std;
int main()
{int choice;
int bezos = 0 , gates = 0 , bugs = 0 ;
int vc = 0 ;
do {
cout<<"\n\n\nEVOTE\n-----"
<<"\n1.Jeff Bezos
<<"\n2.Bill Gates
<<"\n3.Bugs Bunny"
// 4. Print current tally [hidden admin option]
// 5. Print audit trail [hidden admin option]
// 6. mess with the vote [hidden hacker option] E.C.
// 7. END THE ELECTION
<<"\n\n Your selection? ";
cin >> choice ;
if(choice==1) {bezos++ ; vc++ ; cout<<"\nThanks for voting!"; }
if(choice==2) {gates++ ;vc++ ; cout<<"\nThanks for voting!"; }
if(choice==3) { bugs++ ; vc++ ; cout<<"\nThanks for voting!"; }
if((choice<1)||(choice>7))cout<<"\nPlease enter 1-3";
// write what happened to FILES
// Tally.txt (overwrite) bezos x gates x bugs x
// auditTrail.txt ios::app (everything typed) 1 2 3 3 56 -12 4
} while(choice != 7 ) ;
cout<<"\n\nRESULTS:\n--------"
<<"\nTotal Votes Cast This Election: "<< vc
<<"\nJeff Bezos: "<< bezos
<<"\nBill Gates: "<< gates
<<"\nBugs Bunny: "<<bugs;
cout<<"\n\n";
system("pause"); // leave this out if using newer DEV C++
return 0;
}
#include <iostream>
#include <fstream>
using namespace std;
int main(){
int choice;
int bezos = 0 , gates = 0 , bugs = 0 ;
int vc = 0 ;
do {
cout << "\n\n\nEVOTE\n-----"
<< "\n1.Jeff Bezos"
<< "\n2.Bill Gates"
<< "\n3.Bugs Bunny"
// 4. Print current tally [hidden admin option]
// 5. Print audit trail [hidden admin option]
// 6. mess with the vote [hidden hacker option] E.C.
// 7. END THE ELECTION
<<"\n\n Your selection? ";
cin >> choice;
if (choice == 1) { bezos++ ; vc++ ; cout << "\nThanks for voting!"; }
if (choice == 2) { gates++ ; vc++ ; cout << "\nThanks for voting!"; }
if (choice == 3) { bugs++ ; vc++ ; cout << "\nThanks for voting!"; }
if ((choice < 1) || (choice > 7)) cout << "\nPlease enter 1-3";
// write what happened to FILES
// Tally.txt (overwrite) bezos x gates x bugs x
ofstream tally;
tally.open("Tally.txt"); // overwrite
tally << "bezos " << bezos << " gates " << gates << " bugs " << bugs;
tally.close();
// auditTrail.txt ios::app (everything typed) 1 2 3 3 56 -12 4
ofstream auditTrail;
auditTrail.open("auditTrail.txt", ios_base::app); // append instead of overwrite
auditTrail << choice << " ";
auditTrail.close();
} while(choice != 7 );
cout<<"\n\nRESULTS:\n--------"
<< "\nTotal Votes Cast This Election: " << vc
<< "\nJeff Bezos: " << bezos
<< "\nBill Gates: " << gates
<< "\nBugs Bunny: " << bugs;
cout<<"\n\n";
system("pause"); // leave this out if using newer DEV C++
return 0;
}