Could someone find the error that I get on this.


#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.
The easiest is to initialize all variables to 0 when you declare them.
Thank you it worked
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) The error message means that, on line 59, you're trying to use the value of the variable yesvote1, but you haven't actually given it a value.

Now, I know you think you've given it a value. Look more closely at the line where you think you're doing that...
Topic archived. No new replies allowed.