Create a structure to store the product name, rate, and quality. Also, deduct a 10% discount on the total price if the total price exceeds 20,000.
Understand the Problem
The question is asking for a method to create a structured way to store product information, including product name, rate, and quality. Additionally, it requires a rule to apply a discount of 10% on the total price if it exceeds 20,000.
Answer
Use a structure in C to store product name, rate, and quality, and apply a 10% discount if the total price exceeds 20,000.
To store product information including name, rate, and quality, a structure in C could be used. Here's an example:
#include <stdio.h>
struct Product {
char name[50];
float rate;
int quality;
};
float calculate_discounted_price(float total_price) {
if (total_price > 20000) {
total_price -= total_price * 0.1; // Deduct 10% discount
}
return total_price;
}
int main() {
struct Product product;
// Example product setup
strcpy(product.name, "ExampleProduct");
product.rate = 10500; // rate per unit
product.quality = 2; // number of units
float total_price = product.rate * product.quality;
float discounted_price = calculate_discounted_price(total_price);
printf("Product: %s\n", product.name);
printf("Total Price: %.2f\n", total_price);
printf("Discounted Price: %.2f\n", discounted_price);
return 0;
}
In this program, a structure Product
is used to store the product's name, rate, and quality. The calculate_discounted_price
function applies a 10% discount if the total_price
exceeds 20,000.
Answer for screen readers
To store product information including name, rate, and quality, a structure in C could be used. Here's an example:
#include <stdio.h>
struct Product {
char name[50];
float rate;
int quality;
};
float calculate_discounted_price(float total_price) {
if (total_price > 20000) {
total_price -= total_price * 0.1; // Deduct 10% discount
}
return total_price;
}
int main() {
struct Product product;
// Example product setup
strcpy(product.name, "ExampleProduct");
product.rate = 10500; // rate per unit
product.quality = 2; // number of units
float total_price = product.rate * product.quality;
float discounted_price = calculate_discounted_price(total_price);
printf("Product: %s\n", product.name);
printf("Total Price: %.2f\n", total_price);
printf("Discounted Price: %.2f\n", discounted_price);
return 0;
}
In this program, a structure Product
is used to store the product's name, rate, and quality. The calculate_discounted_price
function applies a 10% discount if the total_price
exceeds 20,000.
More Information
In the given solution, a structure helps organize the data related to a product, and conditional logic is used to apply the appropriate discount.
Tips
A common mistake is forgetting to check if the total price condition is met before applying the discount. Ensure the total price is correctly calculated.
AI-generated content may contain errors. Please verify critical information