counter

This is a discussion on counter within the C++ Programming forums, part of the General Programming Boards category; not sure how to get a counter to go up each time a function is selected.So far the loutput is ...

  1. #1
    Beginner
    Join Date
    Apr 2005
    Location
    uk
    Posts
    8

    counter

    not sure how to get a counter to go up each time a function is selected.So far the loutput is 123456789 etc and what i am trying to do is 1 then it clears and goes to 2 etc.

    This is what i have got so far. Any advice ?

    -
    Code:
    addone()
    
    {
    	int t;
    	t = 0;
    	while (t <20)
         {
    		t++;
    	cout <<t;
    	}
    		return 0;
    	}
    --------------------------------

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by Colonial Viper
    not sure how to get a counter to go up each time a function is selected.So far the loutput is 123456789 etc and what i am trying to do is 1 then it clears and goes to 2 etc.

    This is what i have got so far. Any advice ?

    -
    --------------------------------
    change your cout to this:

    Code:
     cout << t << "\r";

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    I think what you are wanting to do clear the screen in between cout's. This is a somewhat controversial topic in that there is no standard way to accomplish this.

    The cheap and easy way (not preferred method) is to use a system( ) command derived from the <csdtlib> library:

    Code:
    addone()
    
    {
    	int t;
    	t = 0;
    	while (t <20)
         {
    		t++;
         
                    system("cls");  //works on windows only 
    
    	cout << t;
    	}
    		return 0;
    	}
    Check this for a better screen-clearing solution.
    Last edited by The Brain; 04-01-2005 at 10:40 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Beginner
    Join Date
    Apr 2005
    Location
    uk
    Posts
    8
    that clears everything,no numbers at all.

  5. #5
    Beginner
    Join Date
    Apr 2005
    Location
    uk
    Posts
    8
    thanks that works better i suppose i will have to put it in a case loop so that each time the function ia accesed it goes up by one otherwise the counter goes up too fast..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 05:36 PM
  2. Page File counter and Private Bytes Counter
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-31-2008, 02:17 AM
  3. Flowchart Question
    By dmkanz07 in forum C Programming
    Replies: 1
    Last Post: 04-08-2007, 11:33 AM
  4. Counter Heap Sort
    By Achillles in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 12:17 PM
  5. how to obtain first character of every other word
    By archie in forum C++ Programming
    Replies: 8
    Last Post: 02-18-2002, 12:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21