I am having trouble reading reading from a file. At the moment I'm not even sure that the rest of my 'if' statements are working since only the first one prints out something when I give it a 'cout'.
The vote.txt file is organized as follows:
ID Number, Age, Gender, Registered, Voted
1812 23 M Y Y
1951 37 F Y Y
4516 15 F N N
1654 19 M Y N
2145 18 F N N
6233 21 F Y Y
9127 22 M N N
3215 26 F Y Y
2201 33 F Y N
7743 41 M Y Y
1121 51 F Y Y
1949 17 M N N
ID Number: is 4 characters
Age: is a number
Gender: is either an F(emale) or a M(ale)
Registered: is either an N(o) or a Y(es)
Vote: is either an N(o) or a Y(es)
With the 'if' statements this is what I'm trying to test to then print out the totals:
Number of males not eligible to register.
Number of females not eligible to register.
Number of males who are old enough to vote but have not registered.
Number of females who are old enough to vote but have not registered.
Number of individuals who are eligible to vote but did not vote.
Number of individuals who did vote.
Number of records processed.
Do my 'if' statements look correct? If not, what should I change? Also, how should I approach the calculations part inside the 'ifs' statements to print the right results?
So far the only thing that I've gotten to work properly is the number of records processed. I would appreciate if someone took the time to tutor me through the completion of this program. Thank you.
This is my code so far:
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
|
/*
age Voter's age
id Voter's ID/4 Digits long
gender Voter's gender/ M(male) or F(female)
reg Registered or not
vote Voted or not
*/
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
ifstream fin;
fin.open("F:\\vote.txt");
int count = 0;
int age, id;
string gender, reg, vote;
while (!fin.eof())
{
fin >> id >> age >> gender >> reg >> vote;
count++;
}
fin.close();
if (age < 18 && gender == "M")
{
}
if (age < 18 && gender == "F")
{
}
if (age >= 18 && gender == "M")
{
}
if (age >= 18 && gender == "F")
{
}
if (age >= 18 && vote == "N")
{
}
if (vote == "M")
{
}
cout << endl << count << "records processed. " << endl;
system("pause");
return 0;
}
|