HELP!!! C programming Calculations

This is a discussion on HELP!!! C programming Calculations within the C Programming forums, part of the General Programming Boards category; Hi Everyone, I'm doing an assignment for uni which is about a small shopping cart. Could some please help me ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    3

    Question HELP!!! C programming Calculations

    Hi Everyone,
    I'm doing an assignment for uni which is about a small shopping cart.
    Could some please help me with these couple of maths calculation issues with c programming please:
    1. If the user inputs a weight that is greater than 2500grams, the charge would be $5.50 + $0.90 for every 400grams over 2500grams, i am able to do the calculate on an separate source code to see it works, but i am unsure how to include it to the original work that i am working on (if that makes any sense....) I have attached the source code for your reference and guidance!!

    Thanking for your help !!!
    Attached Files Attached Files

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,551
    > i am able to do the calculate on an separate source code to see it works,
    So why didn't you post this code as well?

    > else if(weight >= 25000)
    > input1 = 5.50;
    You put the code you have here.

    Code:
        weight = setValidWeight();
        type = setValidType();
        age = setValidAge();
        printf("\n\nThe type is %.2f\n",type);
        printf("The age is %.2f\n",age);
        printf("The Weight is %.2f Grams\n",weight);
        calculateCharge ();
    But calculateCharge() calls these functions again, prompting you for the same responses.

    Consider say
    calculateCharge( weight, type, age );
    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.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you want to integrate the code into one file, make the above file, into a function, and call it from your new program. Make sure your new program has any missing include files that the AssigShell file requires.

    EZ way to do it. If you need help with that, you'll need to post BOTH programs, so we can see what needs to be done.

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    3
    Hi,
    i just want the setValidWeight(); in one of the IF statement to do this; if the input weight is greater than 2500grams, it should cost it has $5.50 + $0.90c for every 400grams over 2500grams
    i did an rough testing program of that in another source file; have attached it for your references....
    Attached Files Attached Files

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    Ugh, your program is so short. Just post the code within [code][/code] bbcode tags instead of attaching a source file. People are less likely to want to wade through a wall of code to help you, and by attaching a source file, you give the impression that you have a wall of code that was too long to post, hence you are less likely to get help.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,551
    What's so hard about putting some braces in your code?

    else if(weight >= 25000)
    input1 = 5.50;

    Becomes
    Code:
        else if(weight >= 25000) {
            input1 = 5.50;
            // now you can put your 4-line calculation here instead.
        }
    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.

  7. #7
    Registered User
    Join Date
    Oct 2012
    Posts
    3
    you could ??
    so u can perform multiple calculations under the IF & ELSE IF statements ??......

    Code:
    else if(weight >= 25000) {
        input1 = weight - 25000;
        input2 = input1 / 400;
        input3 = input2 * 0.90;
    
    return input3;
    }
    is the code above correct ??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with C programming Mathematical Calculations
    By StangFan in forum C Programming
    Replies: 7
    Last Post: 01-15-2010, 04:09 PM
  2. C++ calculations
    By Learner87 in forum C++ Programming
    Replies: 1
    Last Post: 04-29-2008, 08:51 AM
  3. Calculations
    By bumfluff in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2005, 09:01 AM
  4. calculations
    By wayko in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2001, 10:44 AM

Tags for this Thread


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