Multiplication Chart - Little Help

This is a discussion on Multiplication Chart - Little Help within the C++ Programming forums, part of the General Programming Boards category; Ok, I think I pretty much have the majority of it down. All I need to do is add the ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    25

    Multiplication Chart - Little Help

    Ok, I think I pretty much have the majority of it down. All I need to do is add the multiples of each number to the chart, but I'm having a little trouble. * Noob *



    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    
    int main()
    
    {
    
    	int i,t,max,maxA;
    
    
    
    
    
    
    
    	cout << "Enter max number " << endl;
    	cin >> max;
    
    	cout << " x |";
    	
    
    	for (i=1; i<=max; i++)
    	{
    
    		cout <<i<< setw(3);
    	
    		
    
    	}
    cout<< endl;
    cout << " -------------------------------";
    
    
    	
    cout << endl;
    for (i=1; i<=max; i++)
    	{
    
    
    		cout << "    "<<i*max<< setw(3);
    	
    	
    
    	}
    
    for ( i =1; i<=max; i++)
    
    	{
    
    
    cout <<i<<"|"<< endl;
    
    
    
    	}
    
    
    
    
    system("Pause");
    	return 0;
    
    }

    Also, what is a better option than using "systemPause" ?
    Last edited by Zerohero11; 10-17-2005 at 08:07 AM.

  2. #2
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    You can't go back up and print on previous rows (or maybe you can, but I don't know how, and I can't imagine it makes life easier), so don't just go ahead and print the borders, then fill in. You're going to have to print each row all of the way across, then go on to the next one.

    Think about what will be on each row, and how you can accomplish printing each row, one at a time, to the output.

    >Also, what is a better option than using "systemPause" ?

    It's in the FAQ somewhere, but since system() isn't standard, cin.get() is popular.
    There is a difference between tedious and difficult.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    So far I can only get the first line but it won't display right. It keep apearing in front of the horizontal line..


    Code:
    int main()
    
    {
    
    	int i,t,max;
    
    
    
    
    
    
    
    	cout << "Enter max number " << endl;
    	cin >> max;
    
    	cout << " x |";
    	for (i=1; i<=max; i++)
    	{
    		cout << setw(3)<<i;
    
    	}
    	cout << endl; 
    	cout << "-----------------" << endl;
    
    
    
    	for ( i =1; i<=max; i++)
    
    	{
    t = i*max;
    
    cout <<"  "<<i<<"|"<< endl; 
    cout << " " << t <<"\n";
    
    
    	}
    
    
    
    
    
    
    
    system("Pause");
    	return 0;
    
    }

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    Can anyone else give me a few more insiders?

  5. #5
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    Think more about what you want for the output. Don't code it. Just think about what you want the output to be:

    Code:
    x|  1  2  3  4
    ----------------
    1|  1  2  3  4
    2|  2  4  6  8
    3|  3  6  9  12
    4|  4  8  12 16
    AFAIK, once you cout >> endl; you can't go back. So, you're going to have to print this table to the output screen row by row. Right now you're trying to display column by column. Also, the code you posted writes the entries for i*max, which will only be found on the outside edges of your table. Write the table out by hand, only writing the rows, left to right, one at a time. Imagine that once you start on a new line, you can't go back up. Do the same with the 2x2 table, the 5x5 table. Look at the tables you drew, and think about how you drew them. What was the same about them all? What changed when you changed the limits of the table? The answers to these questions will help you write the program.

    You can't write a program effectively if you don't know, at least in general, how you want the program to accomplish the task at hand.

    You're starting out with the right idea; using loops is the way to go, and you've got a good start on the first row of output. (Just a minor formatting issue remains, as far as I can see.)

    If you have trouble taking those steps, or you have problems translating those steps into code, explain where the problem lies and post any changes to the code.
    There is a difference between tedious and difficult.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me find a multiplication toy.
    By QuestionC in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-24-2007, 01:27 PM
  2. ...multiplication using stacks
    By iiwhitexb0iii in forum C Programming
    Replies: 1
    Last Post: 10-09-2006, 02:28 AM
  3. Need help regarding ActiveX Chart Object
    By Hankyaku in forum C++ Programming
    Replies: 2
    Last Post: 02-19-2005, 04:38 PM
  4. multiplication table
    By SpEkTrE in forum C Programming
    Replies: 2
    Last Post: 12-09-2003, 04:46 PM
  5. outputting a ASCII chart
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 02-15-2002, 11:55 AM

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