Thread: C programming assignment help

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    2

    C programming assignment help

    I missed a few days of class and missed a lesson on structures and parameters of functions, i am having difficulties completing and assignment based off of them.

    Ive read my textbook aswell as other resources provided to me but cant seem to figure out what to do. any help would be greatly appreciated.

    Here is the assignment

    The LineItem struct is defined as follows:
    struct LineItem;
    int fruitType;
    double unitPrice;
    int quantity
    An instance of struct LineItem represents part of an order for fruit. The fruitType field stores a numeric code: 1 for apples, 2 for oranges, 3 for bananas. The unitPrice field stores the cost for one fruit. The quantity field stores the number of fruit being ordered.
    Your task is to implement the orderPrice function. It should return the total cost of the LineItem passed as the parameter, which is usually the unit price times the quantity. However, there is a special going on if a customer orders 20 or more bananas, in which case there is a 15% discount, meaning the total cost of the LineItem should be reduced by 15%.




    Here is the code already provided to me

    Code:
    // Don't change the definition of this data type:
    struct LineItem {
        int fruitType;
        double unitPrice;
        int quantity;
    };
    
    
    // Implement this function
    double orderPrice(struct LineItem item) {
        // TODO: add your code here 
        
    }
    I can do most of the computation for the actual assignment i just need help implementing the function, or if somebody could explain what the next step i could take would be.

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Well, the order price is the unit price multiplied by the quantity. It's almost as simple as that, except that there's a special case for bananas, so you need to check the fruit type: if it's banana, factor in the discount. When you're done, just return the order price.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by laserlight View Post
    Well, the order price is the unit price multiplied by the quantity. It's almost as simple as that, except that there's a special case for bananas, so you need to check the fruit type: if it's banana, factor in the discount. When you're done, just return the order price.
    I didn't read the entire text so thought you were joking about bananas... I would say that Apples should have an increase of, let's say, 200% (Apple is always expensive!)...

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Don't know man, I keep seeing people go bananas about apples...
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Programming Assignment?
    By CodingNewb in forum C Programming
    Replies: 3
    Last Post: 11-28-2009, 10:02 PM
  2. C programming assignment
    By nebula1 in forum C Programming
    Replies: 5
    Last Post: 10-05-2009, 10:01 PM
  3. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  4. Help with programming assignment, please!
    By xMEGANx in forum C++ Programming
    Replies: 2
    Last Post: 02-16-2008, 05:29 PM
  5. C++ Programming Assignment Help
    By cplusplus12 in forum C++ Programming
    Replies: 6
    Last Post: 02-04-2006, 10:24 PM

Tags for this Thread