Ask Question
18 December, 13:45

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.

+1
Answers (1)
  1. 18 December, 16:26
    0
    Have in mind that the following code is ofr C + + but I know that whatever the language you are using, you can use the same idea:

    using namespace std;

    int main ()

    {

    int count=0;

    string x;

    while (1)

    {

    cout<<"Enter either goose or duck";

    cin>>x;

    if (x=="Goose") break;

    count++;

    }

    cout<<"Number of Ducks="<
    return 0;

    }

    Another one that is simplier but the language is python is:

    counter = 0while True: line = input () if line = = 'duck': counter + = 1 elif line = = 'goose':breakprint (counter)
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “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. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers