Couting the attempts in a 'while' loop?

Discussion in 'C#' started by HannahMar, Feb 18, 2010.

  1. HannahMar

    HannahMar New Member

    Joined:
    Feb 18, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi there, I am VERY new to programming and I was wondering if there was a way to count the attempts it took a user to guess a correct number (in a while loop) and then display that number back to the console?
     
  2. servalsoft

    servalsoft New Member

    Joined:
    Apr 17, 2010
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    int count = 0;
    while (condition)
    {
    //do something
    ++count; //this line increase the count every time the loop is called
    }
     
  3. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    http://ipankaj.net
    ++count or count++ is depends on what of calculation or logic you are coding!
    because they works in different way!
    :)
     
  4. servalsoft

    servalsoft New Member

    Joined:
    Apr 17, 2010
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    That's right unless neccessary, I usually used pre-increment, ++count; because it performs less calculations hence it is much faster....
     
  5. sai111

    sai111 New Member

    Joined:
    Nov 23, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    tankhuuuuuuuuuuu
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice