4.5 Code Practice

Write a loop that inputs words until the user enters STOP.

After each input, the program should number each entry and print in this format:

#1: You entered______

Can someone please help me with this because I so stuck

Respuesta :

Answer:

The answer to this question is given below in the explanation section.

Explanation:

This program is written in C++.

                                                                         

#include <iostream>

using namespace std;

int main()

{

   

   string word;// variable for taking user input

   int cond;// to set condition true if user preses the stop and exit from loop

   

   cout<<"Enter word: \n";

   cin>>word;

   do// start while loop

   {

       

       

       if(word=="stop" || word =="STOP" || word == "Stop")// if user enter word stop, then program exit

       {

       cond=0;

       

       }

       else//otherwise loop continue

       {

           cout<<" You Entered "+ word +"\n";

           cout<<"Enter word: \n";

           cin>>word;

           cond=1;

       }

   }  

   while(cond == 1);// if user don't enter word "stop" loop run continuesly.  

   cout<<"Program exit";

   

   return 0;

}