please help me with this code..
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: please help me with this code..

  1. #1
    Join Date
    Feb 2012
    Posts
    6

    Unhappy please help me with this code..

    hello please help me..i try run this code to do double dimensional array and looping..i don't have error but the output cant view:

    #include <stdio.h>
    #define num_staff 5
    #define week 4

    int minimum(const int sales[] [week], int staff, int sales_shoes);
    int maximum(const int sales[] [week], int staff, int sales_shoes);
    double average(const int setofSales[], int sales_shoes);
    void printArray(const int sales[][week], int staff, int sales_shoes);
    int loop ( const int sales[][week], int staff, int sales_shoes);
    int main(void)
    {
    int nums_staff;

    const int totalSales[num_staff][week]= {{ 15 , 18 , 16 , 13 },
    {26 , 17 , 19 , 18 },
    {21 , 7 , 13 , 10 },
    {24 , 27 , 15 , 19 },
    { 10 , 20 , 16 , 11 }};

    /* output array statement*/
    printf("THE ARRAY IS:\n");
    printArray(totalSales, num_staff, week);

    /*determine min and max sales value*/
    printf("\n\n min_Sales: %d\n max_Sales:%d\n", minimum(totalSales,num_staff,week),

    maximum(totalSales,num_staff,week));

    for(nums_staff = 0; nums_staff < num_staff; nums_staff++){
    printf("the average sales for number staff %d is %.2f\n", nums_staff, average(totalSales[nums_staff],week));
    }
    return 0;
    }

    int minimum(const int sales[][week],int staff, int sales_shoes)
    {
    int i;
    int j;
    int lowSales = 100;

    for (i= 0; i < staff; i++){
    for (j= 0; j < week; j++){

    if(sales[i][j] < lowSales){
    lowSales = sales[i][j];
    }
    }
    }
    return lowSales;
    }
    int maximum(const int sales [][week],int staff, int sales_shoes)
    {
    int i;
    int j;
    int highSales = 0;
    for(i = 0; i < staff; i++){
    for (j = 0; j < week; j++){
    if(sales[i][j] >highSales){
    highSales = sales[i][j];
    }
    }
    }
    return highSales;
    }
    double average(const int setofsales[], int sales_shoes)
    {
    int i;
    int total = 0;
    for (i =0; i<sales_shoes; i++){
    total +=setofsales[i];
    }

    return(double)total/sales_shoes;
    }

    void printArray(const int sales[][week], int staff, int sales_shoes)
    {
    int i;
    int j;

    printf(" [1] [2] [3] [4]");

    for(i= 0; i < staff; i++){

    printf("\n totalSales[%d]", i);

    for (j= 0; j < sales_shoes; j++){
    printf("%-Sd", sales[i][j]);
    }
    }
    }
    int loop ( const int sales[][week], int staff, int sales_shoes)
    {
    int i;
    int j;
    int lowSales;

    for (i = 0; i < staff; i++){
    for ( j= 0; j < sales_shoes; j++){
    if ( sales[i][j] < lowSales){
    lowSales = sales [i][j];
    }

    }
    }
    return lowSales;
    }

  2. #2
    Join Date
    Jan 2012
    Posts
    33

    Re: please help me with this code..

    Well I did my part...


    Code:
    #include <stdio.h>
    #define num_staff 5
    #define week 4
    
    int minimum(const int sales[] [week], int staff, int sales_shoes);
    int maximum(const int sales[] [week], int staff, int sales_shoes);
    double average(const int setofSales[], int sales_shoes);
    void printArray(const int sales[][week], int staff, int sales_shoes);
    int loop ( const int sales[][week], int staff, int sales_shoes);
    
    
    int main(void)
    {
    	int nums_staff;
    
    	const int totalSales[num_staff][week]= 
    	{{ 15 , 18 , 16 , 13 },
    	 { 26 , 17 , 19 , 18 },
    	 { 21 , 7 , 13 , 10  },
    	 { 24 , 27 , 15 , 19 },
    	 { 10 , 20 , 16 , 11 }};
    
    	/* output array statement*/
    	printf("THE ARRAY IS:\n");
    	printArray(totalSales, num_staff, week);
    
    	/*determine min and max sales value*/
    	printf("\n\n min_Sales: &#37;d\n max_Sales:%d\n", minimum(totalSales,num_staff,week),
    
    	maximum(totalSales,num_staff,week));
    
    	for(nums_staff = 0; nums_staff < num_staff; nums_staff++)
    		printf("the average sales fo number staff %d is %.2f\n", nums_staff, average(totalSales[nums_staff],week));
    
    	return 0;
    }
    
    int minimum(const int sales[][week],int staff, int sales_shoes)
    {
    	int i;
    	int j;
    	int lowSales = 100;
    
    	for (i= 0; i < staff; i++)
    		for (j= 0; j < week; j++)
    			if(sales[i][j] < lowSales)
    				lowSales = sales[i][j];
    
    	return lowSales;
    }
    
    int maximum(const int sales [][week],int staff, int sales_shoes)
    {
    	int i;
    	int j;
    	int highSales = 0;
    	for(i = 0; i < staff; i++)
    		for (j = 0; j < week; j++)
    			if(sales[i][j] >highSales)
    				highSales = sales[i][j];
    
    	return highSales;
    }
    
    double average(const int setofsales[], int sales_shoes)
    {
    	int i;
    	int total = 0;
    	for (i =0; i<sales_shoes; i++)
    		total +=setofsales[i];
    
    	return(double)total/sales_shoes;
    }
    
    void printArray(const int sales[][week], int staff, int sales_shoes)
    {
    	int i;
    	int j;
    
    	printf(" [1] [2] [3] [4]");
    
    	for(i= 0; i < staff; i++)
    	{
    		printf("\n totalSales[%d]", i);
    		for (j= 0; j < sales_shoes; j++)
    			printf("%-Sd", sales[i][j]);
    	}
    }
    
    int loop ( const int sales[][week], int staff, int sales_shoes)
    {
    	int i;
    	int j;
    	int lowSales;
    
    	for (i = 0; i < staff; i++)
    		for ( j= 0; j < sales_shoes; j++)
    			if ( sales[i][j] < lowSales)
    				lowSales = sales [i][j];
    
    	return lowSales;
    }

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,088

    Re: please help me with this code..

    It crashed when I ran it on this line.
    printf("&#37;-Sd", sales[i][j]);

    When I changed it to %d it output something that appeared correct. What do you mean "output can't view"?

    Also noteworthy, the only reason I looked at your code was because kevindckr was kind enough to format it for you. Most of us here will ignore unformatted code or code that's not posted using code tags.
    Last edited by GCDEF; March 8th, 2012 at 02:25 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center