Static local variable and boolean function count

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kinglaplace64220
    New Member
    • Mar 2010
    • 2

    Static local variable and boolean function count

    I need someone to give me the best solution on using a Static variable and a boolean function to keep count of how many times a user made an invalid input in my program
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    This is such a simple requirement that all solutions are likely to be very similar in composition. Selecting the "best" will depend on your definition of best. As you are aware a static variable when included in the body of a loop for example is only referred to when within the first iteration of the loop so.....
    for( ; ; )
    "enter an integer less than 50 or greater than 500 (-99 to quit)"
    enter integer n
    while(n)
    static count =0
    if(n>=50 && n <=500)
    count++
    if(n=-99)break
    "you entered " count " integers outside the range"
    All you have to do now is turn the while loop with a boolean condition into a function of your choice. some condensation might also be appropriate.

    Comment

    Working...