Thread: printing contents of array vertically

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    100

    printing contents of array vertically

    Hi,
    I have written a program from a book I'm learning from. Everything works except for the end when the contents of an array is to be displayed in a table.
    Code:
    #include <stdio.h>
    
    main()
    
    {
    	int sweatshirts[7][4],
                        size,      /*index*/                                                   
                    college;    /*index*/
    
    
    	for(college=0; college<7; ++college)
    	{
    		printf("\nPlease enter the number of sweatshirt sizes for college %d." , college+1);
    			for(size=0; size<4; ++size)
    			{
    				printf("\nSize(%d): " , size+1);
    					scanf("%d" , &sweatshirts[college][size]);
    			}
    
    	}
    
    
    					for(college=0; college<7; ++college)
    					{
    						
    						for(size=0; size<4; ++size)
    						{
    							
    							printf("\n%d " , sweatshirts[college][size]);
    /*this loop is just to test the output numbers are correct*/	
    							if(size == 3)
    							printf("\n");					
    							
    						}
    					}
    
    	
    
    /*output numbers will go in this table in columns under 1-7*/
    
          /*printf("\n                                      College                  \n");
    	printf("\n                       1     2     3     4     5     6     7    Size total        ");
    	printf("\n");
    	printf("\n        Small\n");
    	printf("\n       Medium\n");
    	printf("\nSize\n");
    	printf("\n        Large\n");
    	printf("\n      X_Large\n");
    	printf("\nCollege total\n");
    	printf("\nTotal quantity on hand\n");  */
    	
    			
    
    }
    The table is on the bottom in /*comments*/. The last for loop is just a test to see if the output is correct. But it will eventually be in the table. Problem is I cant get each "size" for each of the 7 "stores" to print out vertically under each numbered column like:
    1 3
    2 4
    3 5
    4 6 I have tried using /t in the for loop to try and make the numbers start in a new position to the right, but no luck.
    Last edited by richdb; 03-08-2006 at 10:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing an array of structs?
    By blernblan in forum C Programming
    Replies: 4
    Last Post: 04-28-2009, 03:04 PM
  2. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Printing an Array to the screen
    By simhap in forum C++ Programming
    Replies: 6
    Last Post: 11-01-2001, 11:16 AM