Thread: Need help fast with counting consecutive occurances

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    2

    Need help fast with counting consecutive occurances

    Hi, I am new to prgramming and am having a little trouble. I need help with I am working on this program...a user inputs an integer between 1 and 100 (for example, 50). I have a for loop that generates random numbers between 1 and 100 and iterates according to another user input. Now i need to figure out the number of consecutive times that a random numbers occurs below or above the user input.
    For example...
    cout<<"What's your number?";
    cin>>50
    cout<<"How many random numbers would you like?";
    cin>>10

    Output: 24 34 54 67 98 12 34 44 99 10 (random numbers)

    This is what I need to figure out...how many times the random numbers occurs consecutively...
    24 and 34 are 2 consecutives below 50
    54, 67, and 98 a 3 consecutives above 50
    12, 34, 44 are 3 consecutives below 50

    Thank you!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well you pretty much wrote the logic of what you want to achieve.

    if this > previous && this <= 50 then increment count, else reset count
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 02-27-2009, 04:43 PM
  2. First Consecutive composites Help
    By ch4 in forum C Programming
    Replies: 10
    Last Post: 11-23-2007, 04:55 PM
  3. Counting String Occurances
    By Lesaras in forum C++ Programming
    Replies: 5
    Last Post: 12-14-2006, 09:43 AM
  4. Super fast bilinear interpolation
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 06-18-2002, 09:35 PM
  5. Detecting two consecutive spaces in string
    By bob2509 in forum C++ Programming
    Replies: 20
    Last Post: 04-22-2002, 01:48 PM