Thread: Further Explanation

  1. #1
    Registered User
    Join Date
    Sep 2001

    Unhappy Further Explanation

    I posted this problem as a last resort to a problem I have been working on for three weeks.

    Here is the problem:

    I have to produce a report with the following:


    Length xxxft
    Width xxxft
    Area xxxft


    Description Cost/SQ.FT Charge/Room

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Carpet xxx.xx $xxxx.xx

    Labor 0.35 xxxx.xx

    - - - - - - - - - - - -

    Installed Price $xxxx.xx
    Discount xx.x% xxxx.xx
    - - - - - - - - - - - - -

    Subtotal $xxxx.xx

    Tax xxxx.xx

    Total $xxxx.xx

    The above is what the report should look like.
    The length & width & carpet price are read in from a data file.
    The area, carpet price is calculated.
    The labor price is given as .35 x area.
    Installed price = carpet charge + labor.
    Discount would be subtracted after installed price is calculated
    After discount is figured, this would give the subtotal.
    Apply tax next and that would give the total.

    I know this sounds like a lot but I am having problems doing the calculalions using pointer as well as reading (scanf()) and displaying (printf()) the length and width.
    I do not know how to approach the problem using pointers and using pointers within a function.

    I don't blame anyone if they skip this problem!!!
    Thank you for at least looking at it.

    I have attached the program that I am working on. All it has is the array portion of the problem that seems to work fine.
    Imagination at Work

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    I assume you know how to use scanf - partly because this is one of those rare examples that actually uses the status result of scanf.

    So if the scanf was in main, you would read an integer like so
    int main ( ) {
        int length;
        scanf( "%i", &length );
        printf( "You entered %d\n", length );
    Now if you want to bury this inside a function, you need to do this.

    void foo ( int *length ) {
        scanf ( "%i", length );   // this is already a pointer
        printf( "You entered %d\n", *length );
    int main ( ) {
        int length;
        foo ( &length );  // pass a pointer
    So if you prototype initialization, processCustomerRecord to have int *length, and call them from main passing &length (where int length is the declaration), then you should be able to make some progress.
    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

Similar Threads

  1. Linked Lists
    By Bleu_Cheese in forum C++ Programming
    Replies: 13
    Last Post: 12-21-2007, 09:17 PM
  2. Explanation of switch statements
    By ammochck21 in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2006, 02:59 PM
  3. printf function explanation
    By vice in forum C Programming
    Replies: 3
    Last Post: 09-21-2005, 08:35 PM
  4. basic linked list declaration..need explanation
    By aspand in forum C Programming
    Replies: 3
    Last Post: 06-07-2002, 05:55 PM
  5. Explanation!!!
    By MITCHELL in forum Windows Programming
    Replies: 4
    Last Post: 10-25-2001, 01:13 AM