C Online Compiler
Example: Basic Profit Calculator in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Basic Profit Calculator #include <stdio.h> int main() { // Step 1: Declare variables to store revenue, expenses, and profit. float revenue; float expenses; float profit; // Step 2: Prompt user for total revenue. printf("Enter total revenue: $"); scanf("%f", &revenue); // Step 3: Prompt user for total expenses. printf("Enter total expenses: $"); scanf("%f", &expenses); // Step 4: Calculate profit. profit = revenue - expenses; // Step 5: Display the calculated profit. printf("--------------------------\n"); printf("Calculated Profit: $%.2f\n", profit); // Step 6: Determine if it's a profit or loss. if (profit > 0) { printf("The company made a profit.\n"); } else if (profit < 0) { printf("The company incurred a loss.\n"); } else { printf("The company broke even.\n"); } return 0; }
Output
Clear
ADVERTISEMENTS