2 Replies - 7320 Views - Last Post: 29 January 2008 - 05:50 PM Rate Topic: -----

#1 beckoningthemoon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-January 08

Count Controlled Loop

Post icon  Posted 29 January 2008 - 05:32 PM

I am having a problem creating a code that allows the user to enter a number, and have a message displayed that number of time. For example, if the user put in the number '6' and the message "Welcome" displayed 6 times. Any help would be awesome. I keep using the while loop, and have even resorted to a do-while loop, but neither work, and I can't cause it to happen repeatedly without it going far over the number. Thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: Count Controlled Loop

#2 cosette_hinds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 30-December 06

Re: Count Controlled Loop

Posted 29 January 2008 - 05:37 PM

View Postbeckoningthemoon, on 30 Jan, 2008 - 10:32 AM, said:

I am having a problem creating a code that allows the user to enter a number, and have a message displayed that number of time. For example, if the user put in the number '6' and the message "Welcome" displayed 6 times. Any help would be awesome. I keep using the while loop, and have even resorted to a do-while loop, but neither work, and I can't cause it to happen repeatedly without it going far over the number. Thanks.


Please show us the code that you are currently using before asking for help with a problem such as this. It enables us to give you advice based on the level of code that you are showing, and also enables us to pick up any errors being made semantically.

For your information however, it is commonly taught to use a "for" loop for counter controlled loops.
Was This Post Helpful? 0
  • +
  • -

#3 Jingle  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 317
  • Joined: 20-October 07

Re: Count Controlled Loop

Posted 29 January 2008 - 05:50 PM

View Postbeckoningthemoon, on 29 Jan, 2008 - 05:32 PM, said:

I am having a problem creating a code that allows the user to enter a number, and have a message displayed that number of time. For example, if the user put in the number '6' and the message "Welcome" displayed 6 times. Any help would be awesome. I keep using the while loop, and have even resorted to a do-while loop, but neither work, and I can't cause it to happen repeatedly without it going far over the number. Thanks.



while( entered_number >= i )
{
printf("Hello World");
i++;
}



something like that you do the rest this is just a start
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1