Thread: C problem

  1. #1
    Registered User
    Join Date
    Oct 2003

    C problem

    Please help me understand what to do with this problem?

    The ABC Mail Order Grocery sells artichokes for $1.25 per pound, beets for .65 per pound, and carrots for .89 per pound. They give 5% discount for orders of $100 or more prior to adding shipping costs. They charge $3.50 shipping and handling for any order of 5 pounds or under, $10.00 shipping and handling for orders over 5 pounds and under 20 pounds, and $8.00 plus .10 per pound for shipments of 20 pounds or more. Write a program to ask the user to enter a single grocery item (a for artichokes, b for beets, and c for carrots) and the weight in pounds. The program then computes the subtotal, the discount, if any, the shipping charges, and the grand total. The program then should display the grocery item purchased, the cost per pound, the pounds ordered, the subtotal, the discount, the shpping charged, and the grand total. I have to run the program for 3 data sets a 100, b 5, and c 7.
    I am having trouble with this problem. I can figure out for one data set, but not grasping how to include the others. Please help. This is what I have so far.

    #include <stdio.h>
    #define artichokes 1.25
    #define beets .65
    #define carrots .89
    void main(void)
    		/*	Declare and intialize variables	*/ 
    {	int lbs;
    	float Sub_Total, Discount, Shipping, Grand_Total;
    	char item;
    		/*	PrintOut  */
    	printf("ABC Mail Order Company\n\n"); 
    	printf("Grocery items:\n");
        printf("     a for artichokes\n");
    	printf("     b for beets\n");
    	printf("     c for carrots\n\n");
    		/*	prompt user for input	*/
        printf("Enter an item and the amount in lbs->");
    	scanf("%c %i", &item, &lbs);
    	printf("%i pounds of artichokes @ $%g per pound\n\n", lbs, artichokes);
    	Sub_Total = lbs  * artichokes;
    	printf("    Sub Total:	 $ %6.2f\n", Sub_Total);
    	Discount = Sub_Total * .05;
    	printf("    Discount:	 - %6.2f\n", Discount);
    	Shipping = 8.00 + lbs * .10;
    	printf("    Shipping:	   %6.2f\n", Shipping);
    	printf("    -------------------------\n");
    	Grand_Total = Sub_Total - Discount + Shipping;
    	printf("    Grand Total: $ %6.2f\n", Grand_Total);

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    void main(void)
    Main returns an int always.

    That aside, what's the problem? You know how to ask for one type, so do the same for the other two.
    printf("What do you want to buy?\n");
    printf("    a) air\n");
    printf("    b) rain\n");
    printf("    c) sunlight\n");
    printf("> ");
    scanf("%c%*c", &choice );
    if( choice == 'a' )
    { stuff for buying air...
    if( choice == 'b' )
    { stuff for buying rain...
    if( choice == 'c' )
    { stuff for buying sunlight...
        ....tell them to pick something real and try again...
    Put it in a loop. Call it a day.

    Hope is the first step on the road to disappointment.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Can you use arrays?
    Can you use structures?

    The problem can made easier if you have the ability to use at least arrays. That way arrays for item, price, shipping can be defined to make the process simple. Structures can make it a little easier.

    If not, quzah's suggestion will work well.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User
    Join Date
    Oct 2003
    No we can't use arrays or any other structures, but thanks for the help and I'll try what was suggested.

  5. #5
    Registered User
    Join Date
    Oct 2003
    I just wanted to thank you guys for the help, I was able to solve the problem with your input, once again, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM