#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main () {
//initialize variables
string filepath;
string name;
char seen;
int age;
int score;
int total1;
int count1;
int total2;
int count2;
int total3;
int count3;
int total4;
int count4;
ifstream infile;
//prompt user for file path
cout << "please enter the full file path:" << "\n";
cin >> filepath;
//opens file
infile.open (filepath.c_str());
//program interprets the file with variables
while (!infile.eof()){
infile >> name >> seen >> age >> score;
//echo file
cout << name << " " << setw(15) << left <<
seen << setw(10) << left <<
age << setw(10) << left <<
score << setw(10) << left <<
endl;
//if statements to separate the brackets of people
//next line gives expected identifier error
if ( age >= 18 ) && ( seen == Y ){
total1 += score;
count1++;
}else if ( age >= 18 ) && ( seen == N ){
total2 += score;
count2++;
}else if ( age <= 18 ) && ( seen == Y ){
total3 += score;
count3++;
}else if ( age <= 18 ) && ( seen == N ){
total4 += score;
count4++;
}
}
cout << score << total1 << total2 << total3 << total4 <<
count1 << count2 << count3 << count4;
infile.close();
getchar();
getchar();
return 0;
}
Attached File(s)
-
results.txt (310bytes)
Number of downloads: 21

New Topic/Question
Reply



MultiQuote




|