-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