Thread: Creating seperate functions for inputs, outputs and calculations?

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

    Creating seperate functions for inputs, outputs and calculations?

    Hi,

    I am used to writing code as 1 function but now I need to split inputs calculations and outputs into seperate functions.

    Could somebody show me how to do this using this code.

    PHP Code:

    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>

    // *********************************************
    // Date - Name - Description
    // 20/10/10 - Toby Curran - Practice
    // *********************************************


    void main()
    {
        
    int Width 0;
        
    int Length 0;
        
    int Offices 0;
        
    int Cost 0;
        
    int Carpet 0;
        
    int Price 0;


        
    printf("Enter the width of the office ");
        
    scanf("%d", &Width);
        
    fflush(stdin);

        
    printf("\nEnter the length of the office ");
        
    scanf("%d", &Length);
        
    fflush(stdin);

        
    printf("\nEnter the number of offices on the floor ");
        
    scanf("%d", &Offices);
        
    fflush(stdin);

        
    printf("\nEnter the price of the carpet per meter square ");
        
    scanf("%d", &Cost);
        
    fflush(stdin);

        
    Carpet Width Length Offices;

        
    printf("\n\nCarpet is: %d"Carpet);

        
    Price Width Length Offices Cost;

        
    printf("\n\nPrice is: %d"Price);

        
    getch();


    Thanks

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    fflush(stdin).
    Question 11.12a
    So have you learnt how to write function?
    If so, show your attempt first.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    2
    I think I have, should it look something like this?

    [TAG]
    void main ()

    {
    GetLength();
    }

    void GetLength ()
    {

    printf("\nEnter the length of the office ");
    scanf("%d", &Length);
    fflush(stdin);
    }
    [\TAG]

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed