It has to do with fstream. It's a survey-like program.
The first and third question need the same answers (Yes or No). It's confusing on how to keep track of the yes's and no's for each individual question since it's one variable that needs to have the same input. Included is the code, and attached is the ifstream text file.
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { string String_Convert_To_Lower( string answer ); int yes = 0; char Keep_Goin; int pc = 0; int mac = 0; int other = 0; int neither = 0; int no = 0; string line; string answer; do{ ifstream in("surveyquestions.txt"); ofstream out("completedsurvey.txt"); while(!in.eof()) { getline(in,line,'\n'); cout << line << '\n'; out << line; cin >> answer; answer = String_Convert_To_Lower(answer); out << answer << '\n'; if(answer == "yes") { yes++; out << "\tYes: " << yes << '\n'; } else if(answer == "no") { no++; out << "\tNo: " << no << '\n'; } if(answer == "pc" || answer == "mac" || answer == "other" || answer == "neither") { if(answer == "pc") { pc++; } else if(answer == "mac") { mac++; } else if(answer == "other") { other++; } else if(answer == "neither") { neither++; } out << "\tPC: " << pc << '\n'; out << "\tMAC: " << mac << '\n'; out << "\tOTHER: " << other << '\n'; out << "\tNEITHER: " << neither << '\n'; } } in.close(); out.close(); int go = 3; if(go == 3) { cout << "Do you want to go (y/n): "; cin >> Keep_Goin; } }while(Keep_Goin == 'y'); return 0; } string String_Convert_To_Lower(string answer) { for( int i = 0; i < answer.length(); i++) { answer.at(i) = tolower(answer.at(i) ); } return answer; }[attachment=745:attachment][attachment=745:attachment][attachment=746:attachment]
Edited by pomp86, 07 May 2005 - 01:31 PM.