编写一个程序,它使用一个char数组和循环来每次读取一个单词,直到用户输入done为止。随后该程序指出用户输入了多少个单词(不包括done在内)
#include
#include
using namespace std;
int main()
{
char word[20];
int num = 0;
cout << "Enter words (to stop, type the word done):" << endl;
cin >> word;
while(strcmp(word , "done") != 0)
{
if(bool(cin >> word) == true)
{
num++;
}
}
cout << "You entered a total of " << num << " words." << endl;
return 0;
}
#include
using namespace std;
int main()
{
char word[20];
int num = 0;
cout << "Enter words (to stop, type the word done):" << endl;
cin >> word;
while(strcmp(word , "done") != 0)
{
if(bool(cin >> word) == true)
{
num++;
}
}
cout << "You entered a total of " << num << " words." << endl;
return 0;
}