Ask 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. after the loop, your code should print out the number of duck strings that were read.

+1
Answers (1)
  1. 23 July, 21:36
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers