136k views
24 votes
The following pseudocode describes how a bookstore computes the price of an order from the total price and the number of the books that were ordered. Step 1: read the total book price and the number of books. Step 2: Compute the tax (7.5% of the total book price). Step 3: Compute the shipping charge ($2 per book). Step 4: The price of the order is the sum of the total book price, the tax and the shipping charge. Step 5: Print the price of the order. Translate this psuedocode into a C Program. Please write only the main body of the program

User Domanskyi
by
4.7k points

2 Answers

5 votes

Final answer:

The provided pseudocode has been translated into a C program that reads the total book price and number of books from the user, computes tax and shipping charges, and then calculates and prints the final order price.

Step-by-step explanation:

To translate the provided pseudocode into a C program, we need to follow the steps closely to compute the final price of an order in a bookstore. The steps include reading in the total book price and number of books, calculating tax, calculating shipping charges, and finally, computing the total price of the order.

Here's an example of how the main body of a C program based on the pseudocode might look:

int main() {
float totalBookPrice, orderPrice, tax;
int numOfBooks;
float shippingCharge;

printf("Enter the total book price: ");
scanf("%f", &totalBookPrice);
printf("Enter the number of books: ");
scanf("%d", &numOfBooks);

tax = totalBookPrice * 0.075;
shippingCharge = numOfBooks * 2;
orderPrice = totalBookPrice + tax + shippingCharge;

printf("The price of the order is: $%.2f\\", orderPrice);

return 0;
}

This program will calculate the total price of the bookstore order by adding the total book price, tax, and shipping charge, then print the price of the order to the console.

User Anindya Sengupta
by
5.6k points
8 votes

Final answer:

In C programming, you can translate the given pseudocode into a program by declaring the necessary variables and performing the required calculations.

Step-by-step explanation:

In C programming, you can translate the given pseudocode into a program as follows:

#include <stdio.h>
int main() {
float total_book_price, tax, shipping_charge, price_of_order;
printf("Enter the total book price: ");
scanf("%f", &total_book_price);
tax = total_book_price * 0.075;
shipping_charge = 2 * total_book_price;
price_of_order = total_book_price + tax + shipping_charge;
printf("Price of the order: $%.2f", price_of_order);
return 0;
}

In this C program, we first declare variables for total_book_price, tax, shipping_charge, and price_of_order. We then read the total_book_price from the user. Next, we calculate the tax by multiplying the total_book_price by 0.075 (7.5%). After that, we compute the shipping_charge by multiplying the total_book_price by 2. Finally, we calculate the price_of_order by adding the total_book_price, tax, and shipping_charge. We then print the price_of_order using printf.

User Peter Walter
by
5.1k points