76.2k views
5 votes
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

1 Answer

3 votes

Answer:

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

Step-by-step 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: \\";

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 +"\\";

cout<<"Enter word: \\";

cin>>word;

cond=1;

}

}

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

cout<<"Program exit";

return 0;

}

User Sudhanshu Patel
by
7.8k points