#include #include #include #include using namespace std; char congress (double p); int main () { ifstream fin; string state; int district; double percent, average; char answer; int totalyes = 0, count = 0; double totalp = 0; // Open the file fin.open("HOUSESEATS.TXT"); if (fin.fail()) { cerr << "File failed to open "; abort(); } cout << "STATE District Percentage Win >60%" << endl; cout << "--------------------------------------------" << endl; while (!fin.eof()) { //and read in the data. fin >> state >> district >> percent; // Call a value returning function that returns ‘y’ //if the representative received more than 60% of the vote and //‘n’ otherwise. answer = congress(percent); cout << state << " " << district << " " << percent << " " << answer << endl; //Compute the total number of delegates winning more than 60% //of the vote. if (answer == 'y') totalyes++; totalp = totalp + percent; count++; } cout << "Total number who won more than 60% of the vote was:" << totalyes << endl; //Compute the average number percentage win. average = totalp/count; cout << "Average Percentage Won: " << average << endl; return 0; } char congress (double p) { if (p > 60) return 'y'; else return 'n'; }