Write a loop that reads strings from standard input where the string is either "duck" or "goose". The loop terminates when "goose" is read in. After the loop, your code should print out the number of "duck" strings that were read.
.
.
Click on the title for the solution
.
.
string duck;
string goose;
string x;
int count = 0;
do
{
cin >> x;
if (x < "goose")
{
count++;
}
}
while (x < "goose");
cout << count;
.
Click on the title for the solution
.
.
This is the answer:
:
string duck;
string goose;
string x;
int count = 0;
do
{
cin >> x;
if (x < "goose")
{
count++;
}
}
while (x < "goose");
cout << count;
No need to declare the duck or goose strings. The "x < "goose"" needs to be x != "goose"
ReplyDelete