Don't understand this with the functions

Homework assignment, don't understand the concept

Page 1 of 1

5 Replies - 761 Views - Last Post: 31 October 2008 - 02:48 AM Rate Topic: -----

#1 bbarker3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 12-October 08

Don't understand this with the functions

Post icon  Posted 30 October 2008 - 09:37 AM

These are the instructions for my assignment. Ignore the parts referring to where to place the assignment in subdirectories and what not. Just focus on the parts in bold. I don't want the assignment done by anyone or anything like that, but like an outline of some sort to help me understand what I am suppose to do.

Place all programs for this assignment in a subdirectory off your home directory on et791. Name this subdirectory assignment_7.
Write a program with functions. First, prompt user for input of three float numbers. Then Use three different functions to calculate maximum(function1), minimum(function2) and median(function3) of these three numbers. Print the returned result in the main() function. Call this program assignment_7a.c.
Modify the assignment_7a.c, take the printing code from the previous program and make another function called display. Call this function to display the maximum, minimum and median. Call this program assignment_7b.c.

Is This A Good Question/Topic? 0
  • +

Replies To: Don't understand this with the functions

#2 schnalf  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 129
  • Joined: 09-February 08

Re: Don't understand this with the functions

Posted 30 October 2008 - 10:07 AM

you have to declare three floats
float number1, number2, number3;


which you can input and output with these functions
void input();
float maximum();
float minimum();
float median();
float display();



whats your problem exactly? did you understand how functions are working? when yes, this assignment would not be a problem for an beginner too.
Was This Post Helpful? 0
  • +
  • -

#3 brds  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: Don't understand this with the functions

Posted 30 October 2008 - 10:07 AM

View Postbbarker3, on 30 Oct, 2008 - 11:37 AM, said:

Write a program with functions. First, prompt user for input of three float numbers. Then Use three different functions to calculate maximum(function1), minimum(function2) and median(function3) of these three numbers. Print the returned result in the main() function.


/* Headers */

/* Min function */

/* Max function */

/* Median function */

/* Main */

int main(void)
{
	/* Get Input */
	
	/* Process Input */

	/* Display Results */

	return 0;
}




View Postbbarker3, on 30 Oct, 2008 - 11:37 AM, said:

Modify the assignment_7a.c, take the printing code from the previous program and make another function called display. Call this function to display the maximum, minimum and median. Call this program assignment_7b.c.


For the second part, take the code to display the results out of main{} and into its own function.
Was This Post Helpful? 0
  • +
  • -

#4 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Don't understand this with the functions

Posted 30 October 2008 - 12:55 PM

View Postbbarker3, on 30 Oct, 2008 - 09:37 AM, said:

These are the instructions for my assignment. Ignore the parts referring to where to place the assignment in subdirectories and what not. Just focus on the parts in bold. I don't want the assignment done by anyone or anything like that, but like an outline of some sort to help me understand what I am suppose to do.

Place all programs for this assignment in a subdirectory off your home directory on et791. Name this subdirectory assignment_7.
Write a program with functions. First, prompt user for input of three float numbers. Then Use three different functions to calculate maximum(function1), minimum(function2) and median(function3) of these three numbers. Print the returned result in the main() function. Call this program assignment_7a.c.
Modify the assignment_7a.c, take the printing code from the previous program and make another function called display. Call this function to display the maximum, minimum and median. Call this program assignment_7b.c.


What college/university are you attending? Curious.
Was This Post Helpful? 0
  • +
  • -

#5 bbarker3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 12-October 08

Re: Don't understand this with the functions

Posted 30 October 2008 - 05:36 PM

View PostHyper, on 30 Oct, 2008 - 12:55 PM, said:

View Postbbarker3, on 30 Oct, 2008 - 09:37 AM, said:

These are the instructions for my assignment. Ignore the parts referring to where to place the assignment in subdirectories and what not. Just focus on the parts in bold. I don't want the assignment done by anyone or anything like that, but like an outline of some sort to help me understand what I am suppose to do.

Place all programs for this assignment in a subdirectory off your home directory on et791. Name this subdirectory assignment_7.
Write a program with functions. First, prompt user for input of three float numbers. Then Use three different functions to calculate maximum(function1), minimum(function2) and median(function3) of these three numbers. Print the returned result in the main() function. Call this program assignment_7a.c.
Modify the assignment_7a.c, take the printing code from the previous program and make another function called display. Call this function to display the maximum, minimum and median. Call this program assignment_7b.c.


What college/university are you attending? Curious.


University of Toledo in Ohio
Was This Post Helpful? 0
  • +
  • -

#6 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: Don't understand this with the functions

Posted 31 October 2008 - 02:48 AM

Here's a C version that takes a little different approach ...
#include <stdio.h>

/*
    A program in C which takes three input integers from the user 
    and displays the minimum, middle and maximum integers 
    given by the user as input.
    
    Uses a simple bubble sort for ordering the numbers.

    Note: C doesn't support passing by ref so easily as C++ does ...
    
    One must pass the address in ... of the object being passed
    then 'catch' that address as a 'pointer' (i.e. an address) for the object

*/

/* Here ... we tell the compiler these are all pointers to int */ 
void sort(int* a, int* b, int* c)
{
    int temp;
    /* 
        using a BUBBLE SORT: first ... 'bubble' the highest to c 
        then 'bubble' the next highest to b ... and we are done  
        
        NOTE: below ... 
        *a and *b take the int values at addresses a and b
        since on the top line we told the compiler 
        that a and b were pointers to (i.e. addresses for) 'int'
    */
    if( *a > *b ) /* swap */
    {
        temp = *a;
        *a = *b;
        *b = temp;
    }
    if( *b > *c ) /* swap */
    {
        temp = *b;
        *b = *c;
        *c = temp;
    }
    if( *a > *b ) /* swap */
    {
        temp = *a;
        *a = *b;
        *b = temp;
    }
 
}
     
int main()
{
    int a=0, b, c, t;
    for(;;)/>
    { 
        printf( "Input 3 non zero integers to be ordered : " );
        a=b=c=0; /* use these zeros as flags for bad data input */ 
        scanf( "%d%d%d", &a, &b, &c );
        while(  (t=getchar()) != '\n' ) ; /* flush stdin */
        
        /* check for bad data ...  */
        if( a==0 || b==0 || c== 0 )
        {
            printf("\nIntegers only ...  ");
            continue; /* from the top of the for loop ...*/
        }
        
        sort( &a, &b, &c ); /* pass addresses to sort function */
        
        printf( "Now in order %d %d %d\n\n", a, b, c );
        
        printf("Press 'Enter' to continue ... 'x' to exit ... ");
        t =getchar();
        if ( t=='x' || t=='X' ) return 0;
        if ( t !='\n') while( (t=getchar()) != '\n' ) ; /* flush stdin */
    }
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1