-3
我很難做到這一點,它就像一個調查,人們必須回答這5個問題,他們的答案(數據)必須保存到一個file.txt然後程序必須讀取數據。然後,讓我們說用戶回答A的第一個問題,就是說,在接受調查答案A的人數(20/100)中,有20個與其他5個問題相同。但即時通訊失去了我不知道如何使程序計數有多少人蔘與調查,以及如何將它們存儲到一個文件中。請幫忙!將數據保存到文件中C++
int questions = 1;
char answer;
for (int i = 0; i < questions; i++){
cout << "\t1 - What kind of phone do you prefer? " << endl;
cout << "\n";
cout << "\ta) Iphone b) Android c) Windows d) Other" << endl;
cout << "\n";
cout << "\tAnswer: ";
cin >> answer;
cout << "\n";
cout << "\t2 - What is your favorite flavor? " << endl;
cout << "\n";
cout << "\ta) Chocolate b) Vanilla c) Strawberry d) Other" << endl;
cout << "\n";
cout << "\tAnswer: ";
cin >> answer;
cout << "\n";
cout << "\t3 - What is your favorite sport? " << endl;
cout << "\n";
cout << "\ta) Baskteball b) Baseball c) Hokey d) Football" << endl;
cout << "\n";
cout << "\tAnswer: ";
cin >> answer;
cout << "\n";
cout << "\t4 - What is your favorite animal? " << endl;
cout << "\n";
cout << "\ta) Cat b) Dog c) Bird d) Other" << endl;
cout << "\n";
cout << "\tAnswer: ";
cin >> answer;
cout << "\n";
cout << "\t5 - What is your favorite season of the year? " << endl;
cout << "\n";
cout << "\ta) Summer b) Winter c) Spring d) Autumn" << endl;
cout << "\n";
cout << "\tAnswer: ";
cin >> answer;
cout << "\n";
}
system("pause");
return 0;
}
所以ü要一個人保存到一個文件?然後計算這些文件? – Quest 2014-10-28 06:03:25