You have been asked to write a program to manage the shopping cart feature of your family’s online business. Your program should work as follows
1. ask the user for the cost of the item to be added to the cart
2. ask the user for the number of such items that should be added to the cart
3. update the new cart total
4. display a message indicating the new cart total and that the item/s have been added to the cart
5. It should ask the user if they want to check out or continue shopping
6. If the user selects to continue shopping, the program should resume from step 1.
7. When the user opts to checkout, the program should print out the current total for the cart,
thank the user for payment and say goodbye
Restrictions:
Please ensure that your program outputs the exact text as in the sample run. Naturally the numeric values will be different, depending on the input used. However the text of the output should be the same.
You may assume that the user always enters a valid float and integer for the price and the number of the item to be added. However, program should not allow the user to enter negative, or 0 values.
You may assume that the user always enters valid input when asked if to continue of checkout.
My probably terrible code:/
//
// main.c
// ShoppingCart
//
// Created by Matt Lovell on 2/9/15.
// Copyright (c) 2015 Matt Lovell. All rights reserved.
//
#include <stdio.h>
int main(int argc, const char * argv[]) {
int number, decision,Y,N;
float price,total,new;
// insert code here...
printf("What is the price of the item that you want to add to cart\n");
scanf("%f",&price);
if(price<=0)
printf("Please enter a price greater than $0.00");
else
printf("how many of the item do you want\n");
scanf("%d",&number);
if(number<=0)
printf("Please enter a number of items greater than 0");
printf("Your item has been added to the cart\n");
total=price*number;
printf("$%.2f has been added to the cart\n",total);
printf("Your new cart total is $%.2f\n",new);
printf("----------------------------------\n");
printf("Would you like to continue shopping? Y for yes, N for no\n");
scanf("%d", &decision);
if (decision==Y)
printf("What is the price of the item that you want to add to cart\n");}
else
printf("You have selected to checkout\nYour bill is $%.2f\nThanks for shopping with us\nGoodbye");
return 0;
}
The problems I'm having is getting it to loop back to the beginning if the user enters Y. Also, its not running through the if statements properly and total isn't being printed. Am I totally off and doing this wrong or have a made a dumb mistake? I appreciate any help or constructive criticism from you guys. You've helped me understand my C problems in the past and its really helped me in my schooling.
Thanks,
-Matt

New Topic/Question
Reply


MultiQuote




|