Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,442 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,313 people online right now. Registration is fast and FREE... Join Now!




loop help

 
Reply to this topicStart new topic

loop help

grimmben
25 Nov, 2007 - 06:13 PM
Post #1

New D.I.C Head
*

Joined: 25 Nov, 2007
Posts: 27


My Contributions
CODE
#include <iostream>

using std::cout;
using std::endl;
using std::cin;

int main()
{
    //declare variable
    int counter = 1;
    int HELLO = 0;
    
    
        //perform loop
    while (HELLO>=1)
    {
        cout << "HELLO" << HELLO << endl;
        
    }//end while
    return 0;
}   //end of main function


it has to display hello 10 times

Mode edit: added code tags: code.gif
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Loop Help
25 Nov, 2007 - 06:33 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
you need to have something that increments HELLO... for example add: HELLO++; inside the loop.

Then you need to set the exit condition for you loop so that it exits when hello is printed 10 times...
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Loop Help
25 Nov, 2007 - 06:44 PM
Post #3

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,025



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
Mentally walk your logic. The very first entry reads while (0>=1). Well, 0>=1 is simply not true, so you never get to print anything; do not pass go.

This one actually so simple you may not find the answer, so I'll offer it.

try this:
CODE

int counter = 0;
while (counter < 10) {
   cout << "HELLO: " << counter << endl;
   //Important, you MUST increment counter or the loop will run forever
   counter++;
}


Hope this helps.

User is online!Profile CardPM
+Quote Post

grimmben
RE: Loop Help
25 Nov, 2007 - 06:56 PM
Post #4

New D.I.C Head
*

Joined: 25 Nov, 2007
Posts: 27


My Contributions
QUOTE(NickDMax @ 25 Nov, 2007 - 07:33 PM) *

you need to have something that increments HELLO... for example add: HELLO++; inside the loop.

Then you need to set the exit condition for you loop so that it exits when hello is printed 10 times...

[size=5]
THANK You!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
User is offlineProfile CardPM
+Quote Post

ajaymatrix
RE: Loop Help
25 Nov, 2007 - 07:47 PM
Post #5

D.I.C Regular
Group Icon

Joined: 15 May, 2007
Posts: 389



Thanked: 1 times
Dream Kudos: 100
My Contributions
use directly a for loop and increment the counter and print..
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 02:11PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month