Thread: Passing In Value

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    16

    Passing In Value

    I'm trying to pass in a value of 3 into the function. Pls help.

    http://img14.imageshack.us/img14/1778/83284975.png

    Uploaded with ImageShack.us

    Code:
    #include<stdio.h>
    
    double Total_Fee(double StudentFee);
    
    void main()
    {
    	double StudentFee[2][1];
    
    	double total;
    
    	int i,j;
    
    	for(i=0;i<2;i++)
    	{
    		for(j=0;j<1;j++)
    		{
    			printf("Enter number>");
    			scanf("%lf",&StudentFee[i][j]);
    		}
    	}
    
    	total=Total_Fee(StudentFee[i][j]);
    
    	printf("%0.2lf\n",total);
    }
    
    double Total_Fee(double StudentFee)
    {
    	double total=0;
    
    	int i;
    
    	for(i=0;i<2;i++)
    	
    		total+=StudentFee;
    
    	return total;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I really hope there's a reason you're array is as weird as it is.

    Anyway, when you get to the end of the loop i is 2 and j is 1 and StudentFee[2][1] just plain doesn't exist. You have to use a value that exists.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    72
    Youpi

    Code:
    #include<stdio.h>
    
    double Total_Fee(double StudentFee);
    
    void main()
    {
    	double StudentFee[2][1];
    
    	double total;
    
    	int i,j;
    
    	for(i=0;i<2;i++)
    	{
    		for(j=0;j<1;j++)
    		{
    			printf("Enter number>");
    			scanf("%lf",&StudentFee[i][j]);
    			total=Total_Fee(StudentFee[i][j]);
    		}
    	}
    
    	//total=Total_Fee(StudentFee[i][j]);
    
    	printf("%0.2lf\n",total);
    }
    
    double Total_Fee(double StudentFee)
    {
    	double total=0;
    
    	int i;
    
    	for(i=0;i<2;i++)
    	
    		total+=StudentFee;
    
    	return total;
    }

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    16
    Thank you :-)

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing Argument from incompatible pointer type
    By AmritxD in forum C Programming
    Replies: 3
    Last Post: 08-15-2010, 03:23 PM
  2. Passing Arguments
    By bolivartech in forum C Programming
    Replies: 13
    Last Post: 10-15-2009, 01:31 PM
  3. Newb Question on Passing Objects as Parameters
    By Mariano L Gappa in forum C++ Programming
    Replies: 12
    Last Post: 11-29-2006, 01:08 PM
  4. Passing by reference not always the best
    By franziss in forum C++ Programming
    Replies: 3
    Last Post: 10-26-2005, 07:08 PM
  5. passing by address vs passing by reference
    By lambs4 in forum C++ Programming
    Replies: 16
    Last Post: 01-09-2003, 01:25 AM