Oct 9, 2017 at 5:26pm UTC
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
char vote1, vote2, vote3, vote4, vote5, vote6;
int yesvote1;
int yesvote2;
int yesvote3;
int yesvote4;
int yesvote5;
int yesvote6;
int totalyes;
int novote1;
int novote2;
int novote3;
int novote4;
int novote5;
int novote6;
int totalno;
ifstream infile;
ofstream outfile;
infile.open("votes.txt");
outfile.open("votesout.txt");
infile >> vote1 >> vote2 >> vote3 >> vote4 >> vote5 >> vote6;
if (vote1 == 'y')
yesvote1 == 1;
else if (vote1 == 'n')
novote1 = 1;
if (vote2 == 'y')
yesvote2 = 1;
else if (vote2 == 'n')
novote2 = 1;
if (vote3 == 'y')
yesvote3 = 1;
else if (vote3 == 'n')
novote3 = 1;
if (vote4 == 'y')
yesvote4 = 1;
else if (vote4 == 'n')
novote4 = 1;
if (vote5 == 'y')
yesvote5 = 1;
else if (vote5 == 'n')
novote5 = 1;
if (vote6 == 'y')
yesvote6 = 1;
else if (vote6 == 'n')
novote6 = 1;
totalyes = yesvote1 + yesvote2 + yesvote3 + yesvote4 + yesvote5 + yesvote6;
totalno = novote1 + novote2 + novote3 + novote4 + novote5 + novote6;
outfile << "Total Number of Votes Yes:" << totalyes << endl;
outfile << "Total Number of Votes No: " << totalno << endl;
infile.close();
outfile.close();
system("pause");
return 0;
}
Error: Line 59 Uninitialized Variable 'yesvote1' used.
Oct 9, 2017 at 5:29pm UTC
The easiest is to initialize all variables to 0 when you declare them.