Delay Timer

This is a discussion on Delay Timer within the C++ Programming forums, part of the General Programming Boards category; I am trying to get this multiplication table to display one line at a time and the timer syntax's that ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    5

    Question Delay Timer

    I am trying to get this multiplication table to display one line at a time and the timer syntax's that I have been using just doesn't seem to work. I have used a wait while loop, a pause delay function, and a couple of other attempts of which none have worked correctly. I don't know if I am not using the right thing or if I am not putting them in the right place or what. Could someone help me please?
    Code:
    void choiceC()
    {
        system("cls");
    	
    // create a 2D array "multi" of integer data type
        int multi[12][12];
        cout << "\n\t\t\t**MULTIPLICATION TABLE**\n\n";
        cout <<"            ";
    //set up horizontal grid numbering 1 thru 12
        for (int x = 0; x < 12; x++)
            {
    	cout.width(5);
    	cout << x+1;
            }
        cout << "\n";
        cout <<"            ";
    //set up underscore line for horizontal grid
        for (int y = 0; y < 60; y++)
    	{
    	    cout<< "_";
    	}
        cout << "\n";
    //set vertical grid numbering 1 thru 12 and vertical grid line
         for (int row = 0; row < 12; row++)
    	{
    	        cout.width(5);
    	        cout << row +1 << " x ? ="<< "|";
    	  for (int col = 0; col < 12; col++)
    	         {
    //displays table of multiplication (i.e. 1x1; 1x2; 1x3;12x12;etc.)
    		multi[row][col] = (row+1)*(col+1);
    		cout.width(5);
    		cout << multi[row][col];
    	         }	
    		cout << "\n";
    	}
        cout << "\n";	
    // end of choice C program
    }
    Last edited by Dena; 03-03-2002 at 05:42 PM.

  2. #2
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    857
    please, what does all the variables do?? A code without comments is very hard to understand...

    now, put your code into the [code] tag so we can read it (indentations)...
    Yoshi

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    5
    I am having a hard time figuring out how to put into the code[tag].

  4. #4
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    [ code ]

    your code

    [ /code ]

    Code:
    without the spaces in the brackets
    bz out...
    Blue

  5. #5
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    consider using iomanip for your table

    Code:
    #include <iomanip>
    #include <iostream>
    using namespace std;
    
    int main()
    {
       int i;
    
       for (i=26;i>=0;--i)
            cout << endl;
    
       cout    << setw(33) << "Iomanip allows you to  "  << endl
               << setw(33) << "line up your text in a "  << endl
               << setw(33) << "better fashion than you"  << endl
               << setw(33) << "are trying to to use.  "  << endl
               << setw(33) << "Iomanip counts back-   "  << endl
               << setw(33) << "ward from the last     "  << endl
               << setw(33) << "character so in this   "  << endl
               << setw(33) << "case the text is 10    "  << endl
               << setw(33) << "spaces from the left   "  << endl
               << setw(33) << "hand side.  Spaces do  "  << endl
               << setw(33) << "count as characters...."  << endl;
    
    return 0;
    }
    Blue

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    5
    I took your suggestion and instead of putting it in 'main' I put it in the 'choice c' function and this is how I did it. I still don't get a delay. Did I do it wrong or put it in the wrong place or.....?
    Code:
    // choice C program Multiplication Table__________________________________________________________
    void choiceC()
    {
    	system("cls");
    	
    // create a 2D array "multi" of integer data type
    	int multi[12][12];
    	int i;
    	for (i=26; i>=0; --i)
    		cout << endl << setw(33);
    	cout << "\n\t\t\t**MULTIPLICATION TABLE**\n\n";
    	cout <<"            ";
    	for (int x = 0; x < 12; x++)
    		{
    			cout.width(5);
    			cout << x+1;
    		}
    	cout << "\n";
    	cout <<"            ";
    	
    	for (int y = 0; y < 60; y++)
    		{
    			cout<< "_";
    		}
    	cout << "\n";
    		
    	for (int row = 0; row < 12; row++)
    		{
    			
    			cout.width(5);
    			cout << row +1 << " x ? ="<< "|";
    			for (int col = 0; col < 12; col++)
    			{
    				multi[row][col] = (row+1)*(col+1);
    				cout.width(5);
    				cout << multi[row][col];
    			}	
    			cout << "\n";
    		}
    	cout << "\n";	
    // end of choice C program
    }

  7. #7
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    first thing I would do if I were you is to break this problem up into smaller workable portions.

    write a little program that displays a line of a multiplication (1 X 1 = 1).

    write a little program that places a table header in a position that you want.

    write a little program....

    these can be small 5-6 line programs.

    Take what you learn from those. Write your function.
    Blue

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    This might work.
    Code:
    // choice C program Multiplication  Table__________________________________________________________
    void choiceC()
    {
    	system("cls");
    	
    // create a 2D array "multi" of integer data type
    	int multi[12][12];
    	int i;
    	for (i=26; i>=0; --i)
    		cout << endl << setw(33);
    	cout << "\n\t\t\t**MULTIPLICATION TABLE**\n\n";
    	cout <<"            ";
    	for (int x = 0; x < 12; x++)
    		{
    			cout.width(5);
    			cout << x+1;
    		}
    	cout << "\n";
    	cout <<"            ";
    	
    	for (int y = 0; y < 60; y++)
    		{
    			cout<< "_";
    		}
    	cout << "\n";
    		
    	for (int row = 0; row < 12; row++)
    		{
    			
    			cout.width(5);
    			cout << row +1 << " x ? ="<< "|";
    			for (int col = 0; col < 12; col++)
    			{
    				multi[row][col] = (row+1)*(col+1);
    				cout.width(5);
    				cout << multi[row][col];
    			}	
    			cout << "\n";
                            cin.get();
                            //getch();
    		}
    	cout << "\n";	
    // end of choice C program
    }
    You can use either cin.get() or getch(). I have the getch() commented. If your compiler has getch(), it would be in <conio.h>

  9. #9
    Registered User
    Join Date
    Feb 2002
    Posts
    5
    Thank you very much! Your last code suggestion worked wonderfully. Thank you very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 12:23 AM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  3. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  4. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 04:18 PM

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