Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a loop that reads strings from standard input where the string is either \

ID: 3654054 • Letter: W

Question

Write a loop that reads strings from standard input where the string is either "land", "air", or "water". The loop terminates when "xxxxx" (five x characters) is read in. Other strings are ignored. After the loop, your code should print out 3 lines: the first consisting of the string "land:" followed by the number of "land" strings read in, the second consisting of the string "air:" followed by the number of "air" strings read in, and the third consisting of the string "water:" followed by the number of "water" strings read in. Each of these should be printed on a separate line.

Explanation / Answer

Please rate...

Program:

================================================

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    string land="land";
    string air="air";
    string water="water";
    int l=0,a=0,w=0;
    while(true)
    {
        cout<<"Enter string: ";
        cin>>s;
        if(s.compare(land)==0)l++;
        if(s.compare(air)==0)a++;
        if(s.compare(water)==0)w++;
        if(s.compare("xxxxx")==0)break;
    }
    cout<<"Land: "<<l;
    cout<<" Air: "<<a;
    cout<<" Water: "<<w;
}

=================================================

Sample output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote