Thread: using void functions

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    8

    using void functions

    hi. i am having a problem using the void function to put a box around the results and display the results. here is the code i made:

    Code:
    #include <stdio.h>
    void display_results(int, int, int);
    
    int main()
    {
    
    	int die1, die2, die3;
    
    	die1 = 1+6;
    	die2 = 3+4;
    	die3 = 2+8;
    	
    	display_results();
    
    return 0;
    }
    
    void display_results(int die1, int die2, int die3){
    	printf("+-------------------------------------+\n");
    	printf("|    Die 1      |        |     Die 2       |\n");
    	printf("|	 %d       |  %d  |	%d      |\n", die1, die3, die2);
    	printf("+-------------------------------------+\n");
    }
    the output should be
    Code:
    +-------------------------------------+
    |    Die 1       |           |     Die 2  |
    |       7         |    10    |      7       |
    +-------------------------------------+


    thanks for any help
    Last edited by amie001; 06-06-2011 at 11:55 PM. Reason: andrew hunter noticed inconsistency

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Code:
    #include <stdio.h>
    void display_results(int, int, int);
    
    int main()
    {
    
    	int die1, die2, die3;
    
    	die1 = 1+6;
    	die2 = 3+4;
    	die3 = 2+8;
    	
    	display_dice();
    
    return 0;
    }
    
    void display_results(int die1, int die2, int die3){
    	printf("+-------------------------------------+\n");
    	printf("|    Die 1    |        |     Die 2    |\n");
    	printf("|	 %d       |  %d  |	%d         |\n", die1, die3, die2);
    	printf("+-------------------------------------+\n");
    }
    Any special reason you are changing the name of the function?

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If you plan on having your box insert a variable width number into the middle of it, and if you want your sides to line up still, you should be using something like %2d (or whatever width you want). Read up on the format specifiers for printf.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void returning functions.
    By admin in forum C++ Programming
    Replies: 3
    Last Post: 05-31-2011, 11:31 PM
  2. C void functions-- help please?
    By shane981 in forum C Programming
    Replies: 3
    Last Post: 03-28-2008, 07:07 AM
  3. Void Functions
    By MyntiFresh in forum C++ Programming
    Replies: 10
    Last Post: 07-13-2005, 06:47 AM
  4. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  5. Void functions
    By cap in forum C Programming
    Replies: 16
    Last Post: 09-04-2002, 08:08 AM