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.

Respuesta :

Answer:

// Program is written in C++

// Comments are used for explanation purpose

// Program starts here

int main()

{

// DECLARE VARIABLES

string word;

int kount = 0;

// Take input

cout<<"Enter duck or goose";

cin>word;

// Checking if word is goose or not

if(word = "goose")

{

cout<<"Ducks = 0";

}

else{

// Loop starts here

while(string == "ducks")

{

kount++;

cin>>word;

}

cout<<"Ducks = "<<kount;

}

return 0;

}