C Online Compiler
Example: Internet Billing Calculator in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Internet Billing Calculator #include <stdio.h> int main() { // Step 1: Declare variables for plan details and customer usage float baseCost; // Base cost of the internet plan int dataLimitGB; // Data limit included in the base plan (in GB) float overageRatePerGB; // Cost per GB for data exceeding the limit int monthlyUsageGB; // Customer's actual monthly data usage (in GB) float totalBill; // Calculated total monthly bill // Step 2: Get plan details from the user printf("--- Internet Billing Plan Setup ---\n"); printf("Enter base monthly cost of the plan: $"); scanf("%f", &baseCost); printf("Enter data limit included in plan (in GB): "); scanf("%d", &dataLimitGB); printf("Enter overage rate per GB (e.g., 1.50 for $1.50/GB): $"); scanf("%f", &overageRatePerGB); // Step 3: Get customer's monthly data usage printf("\n--- Customer Usage Input ---\n"); printf("Enter customer's monthly data usage (in GB): "); scanf("%d", &monthlyUsageGB); // Step 4: Calculate the total bill based on usage if (monthlyUsageGB <= dataLimitGB) { // If usage is within the limit, bill is just the base cost totalBill = baseCost; printf("\nUsage is within the %.0d GB limit.\n", dataLimitGB); } else { // If usage exceeds the limit, calculate overage charges int overageGB = monthlyUsageGB - dataLimitGB; float overageCharge = overageGB * overageRatePerGB; totalBill = baseCost + overageCharge; printf("\nUsage exceeded the limit by %d GB.\n", overageGB); printf("Overage charge: $%.2f\n", overageCharge); } // Step 5: Display the total monthly bill printf("----------------------------------\n"); printf("Base Plan Cost: $%.2f\n", baseCost); printf("Monthly Data Usage: %d GB\n", monthlyUsageGB); printf("Total Monthly Bill: $%.2f\n", totalBill); printf("----------------------------------\n"); return 0; }
Output
Clear
ADVERTISEMENTS