In: Computer Science
In the space provided below write a C program that computes the total cost of items you want to order online. It does so by first asking how many items are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then adds a 5% delivery charge for standard delivery if the total is below $1,000, and an additional 10% charge if you want an expedited next day delivery.
Explanation:
Here is the code which takes the number of items from the user and the price of all the items from the user also.
Then total is calculated and the standard charges are added if the amount is above 1000, after that, it is asked if the user wants next day delivery or not.
If yes, additional 10% is added to the total.
Code:
#include <stdio.h>
int main()
{
int n;
printf("Enter no. of items in cart: ");
scanf("%d", &n);
float sum = 0;
for (int i = 0; i < n; i++) {
float price;
printf("Enter price of item %d: ", i+1);
scanf("%f", &price);
sum = sum + price;
}
float total = sum;
if(sum>1000)
{
total = total + (total/20.0);
}
char next_day;
printf("Do you want next day delivery?(y/n) ");
scanf(" %c", &next_day);
if(next_day == 'y')
{
total = total + (total/10.0);
}
printf("Total charges are %f\n", total);
return 0;
}
output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!