#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int count=0;
void main ()
{
double totM, //total male population
totF, //total female population
old_m=0, //total males over 70
old_f=0, //total females over 70
tot, //total population
tot_m, //total males
tot_f, //total female
i_s_m, //input status male
i_s_f, //input staus female
age=0, //person' age
x=0,y=0,i=0; //counters
char gender, //gender
m='m', //male
f='f', //female
ch;
string str;
ofstream fout;
ifstream fin;
fin.open("town_data.txt", ios::in);
fout.open("town_out.txt", ios::out);
if(!fin){
cout << "Cannot open file.";
exit (1);
}
cout<<"This program will print the population percentage of males and females"
<<"over 70 and the total number of people to the file town_data.txt.";
fout<<"This program will print the population percentage of males and females"
<<" over 70 and the total number of people to the file town_data.txt."<<endl<<endl;
while(fin){
if((gender=m)&&(age>=70))
{
x++;
old_m=x;
fout<<old_m<<endl;
}
else if((gender=f)&&(age>=70))
{
y++;
old_f=y;
fout<<old_f<<endl;
}
}
fin.close();
fout.close();
cin>>ch;
}
Alright. I have been hacking this apart for the last few hours and heres what I have ended up with so far.
I am taking this list of data (sorry if this doesn't line up properly):
f 70
m 48
m 17
f 26
m 73
f 52
m 76
f 37
where 'f' is for female and 'm' is for male. The second column is the age. I want to b able to take the percentage of males older than 70 and the percentage of females older than 70 and the total percentage older than 70. I only know of a few loops and every one that I try seems to get hung up on the first line-f 70- and then exists after each line of data is processed. I used to have a while loop counting the lines of data but it was taken out. I realize I have a bunch of extra variables. Those will be needed later, my one roadblock is getting the number of males, females and everyone older than 70 into its own variable.

New Topic/Question
Reply



MultiQuote


|