2 Replies - 844 Views - Last Post: 01 March 2009 - 11:53 AM Rate Topic: -----

#1 onclue38  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 28-February 09

help understanding c++ do-while loop

Posted 01 March 2009 - 11:34 AM

I have a question? I need help with finding the right way to do this.

do 
{
    cout << name1 <<"The first and third letters are: " << endl;
    cout << name2 <<"The frist and thrid letters are: " << endl;
    cout << name3 <<"The First and Third letters are: " << endl;
    cout << name4 <<"The First and third letters are: " << endl;
    cout << name5 <<"The First and third letters are: " << endl;
} while


*** MOD EDIT: Added code tags. Please :code: ***

Is This A Good Question/Topic? 0
  • +

Replies To: help understanding c++ do-while loop

#2 crazyjugglerdrummer  Icon User is offline

  • GAME OVER. NERD WINS.
  • member icon

Reputation: 119
  • View blog
  • Posts: 690
  • Joined: 07-January 09

Re: help understanding c++ do-while loop

Posted 01 March 2009 - 11:38 AM

A C++ string is basically a vector of chars, and you can use [] to access vectors just like arrays. Something like
 cout << name1 <<"The first and third letters are: " << name1[0] << " and " << name1[2] << endl;



Hope this helps!

Here's some more stuff on C++ char extraction and the like: here
Was This Post Helpful? 1
  • +
  • -

#3 bodom658  Icon User is offline

  • Villiage Idiom
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,123
  • Joined: 22-February 08

Re: help understanding c++ do-while loop

Posted 01 March 2009 - 11:53 AM

in addition, a do-while loop, which it appears you have tried to set up, works like this:

do {
// code goes here
}while(//condition);



Remember that a do while loop will always execute at least once.

and please post all code between the code tags, being code and /code inside []'s, the foremost at the beginning of your code, and the latter at the end.

Feel free to ask more questions if you have any

~Bodom
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1