1 Replies - 476 Views - Last Post: 19 November 2011 - 04:12 PM Rate Topic: -----

#1 abby11   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 15-October 11

Issue with String Output Using While and Nested For Loop

Posted 19 November 2011 - 02:09 PM

Hi All,

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:
#include <iostream>
#include<string>
using namespace 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");
}


Here is the current output:


Inform of working?-Inform of working?-Inform of
working?-Inform of working?-Inform of working?-Inform of
working?-Inform of working?-Inform of working?-Inform of
working?-Inform of working?-



Here is the output I need:

Inform-Inform-Inform-Inform-Inform-Inform-Inform-Inform-Inform-Inform-Inform-Inform-Inform-Inform-Inform-
of-of-of-of-of-of-of-of-of-of-of-of-of-of-of-
working?-working?-working?-working?-working?-working?-working?-working?-working?-working?-working?-working?-working?-working?-working?-


Please let me know where I am going wrong here. Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Issue with String Output Using While and Nested For Loop

#2 abby11   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 15-October 11

Re: Issue with String Output Using While and Nested For Loop

Posted 19 November 2011 - 04:12 PM

nevermind figured her out, had to ignore the spaces between words.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1