C Online Compiler
Example: Circuit Board Selling Price Calculator in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Circuit Board Selling Price Calculator #include <stdio.h> int main() { // Step 1: Declare variables to store cost, profit margin, and selling price. float manufacturingCost; float profitMarginPercentage; // As a percentage, e.g., 25 for 25% float sellingPrice; // Step 2: Prompt the user to enter the manufacturing cost. printf("Enter the manufacturing cost of the circuit board ($): "); scanf("%f", &manufacturingCost); // Step 3: Prompt the user to enter the desired profit margin percentage. printf("Enter the desired profit margin percentage (e.g., 25 for 25%%): "); scanf("%f", &profitMarginPercentage); // Step 4: Calculate the selling price. // Convert percentage to decimal (e.g., 25% -> 0.25) float profitMarginDecimal = profitMarginPercentage / 100.0; sellingPrice = manufacturingCost * (1 + profitMarginDecimal); // Step 5: Display the calculated selling price. printf("\n--- Calculation Result ---\n"); printf("Manufacturing Cost: $%.2f\n", manufacturingCost); printf("Profit Margin: %.2f%%\n", profitMarginPercentage); printf("The calculated selling price is: $%.2f\n", sellingPrice); return 0; }
Output
Clear
ADVERTISEMENTS