Question

In: Computer Science

In the space provided below write a C program that computes the total cost of items...

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.  

Solutions

Expert Solution

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!


Related Solutions

In the space provided below write a C++ program that computes the total cost of books...
In the space provided below write a C++ program that computes the total cost of books you want to order from an online bookstore. It does so by first asking how many books are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then calls two functions: one for computing the taxes and another for computing the delivery charges. The function which computes delivery charges works as...
In the space provided below write a C ++ program that computes the total amount of...
In the space provided below write a C ++ program that computes the total amount of money you are depositing in your bank account. Your program does this by asking you to first enter the number and amount of each check you are depositing, and then it asks you to enter the type of cash bills being deposited and how many of each type, also the types of coins being deposited, and the number of each coin type.
In the space provided below write a C program that computes the total amount of money...
In the space provided below write a C program that computes the total amount of money you have stored in your piggy bank. Your program does this by asking you for number of pennies, nickels, dimes, and quarters in the piggy bank and then displays how much money in total is in the piggy bank.
In the space provided below write a C++ program that asks the user to enter their...
In the space provided below write a C++ program that asks the user to enter their quarterly earnings for the past two years stores the data in a 2-dimensional array. The program then computes both the annual earnings as well as the total earning and prints the results along with the 2-dimensional array on screen as well as onto a file.
C++ program that runs on Visual Basic that computes the total cost of books you want...
C++ program that runs on Visual Basic that computes the total cost of books you want to order from an online bookstore. It does so by first asking how many books are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then calls two functions: one for computing the taxes and another for computing the delivery charges. The function which computes delivery charges works as follows: It...
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Using C Language Write a program segment that computes 1 + 2 + 3 + ......
Using C Language Write a program segment that computes 1 + 2 + 3 + ... + ( n - 1) + n , where n is a data value. Follow the loop body with an if statement that compares this value to (n * (n + 1)) / 2 and displays a message that indicates whether the values are the same or different. Please give me code to just copy and paste
Write a program in C++ that computes the sum of odd numbers between 1 and 117....
Write a program in C++ that computes the sum of odd numbers between 1 and 117. Execute the program and submit a screen capture of the program and its results.
C++ Overloaded Hospital Write a program that computes and displays the charges for a patient’s hospital...
C++ Overloaded Hospital Write a program that computes and displays the charges for a patient’s hospital stay. First, the program should ask if the patient was admitted as an in-patient or an out-patient. Please keep asking the user until the user enters the valid choice. Please refer to the test cases for more details. If the patient was an in-patient the following data should be entered: • The number of days spent in the hospital • The daily rate •...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT