Creating seperate functions for inputs, outputs and calculations?

This is a discussion on Creating seperate functions for inputs, outputs and calculations? within the C Programming forums, part of the General Programming Boards category; Hi, I am used to writing code as 1 function but now I need to split inputs calculations and outputs ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21