Ask Question
8 September, 06:28

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.

+4
Answers (1)
  1. 8 September, 09:14
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers