I am having a bit of trouble with this program. I am supposed to use a while loop to get a string of words from the user. Then using nested for loops I am to dis[play the word 10 times. IF the user enters the word stop the program ends. The program works for displaying 1 word but I need it to display each word in the string separately for the correct number of loops. Also each word has to have a '-' following it.
Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include<string>
usingnamespace std;
int main()
{
string line="";
getline(cin,line);
do
{
for (int i=1;i<=10;i=i+1)
cout << line<<"-";
return(0);
}while(line!="stop");
}
getline (cin, line) Stores the entire line of input in the line variable. You want to separate each word from the input somehow. For example, maybe you could store each word into an array using a for loop which looks for spaces to tell when each word ends.