Sunday, March 30, 2025

C program that calculates the total amount received in cash and online

 Here's a simplified C program that calculates the total amount received in cash and online:


Total Amount Calculator

```

#include <stdio.h>


// Define structure for payment methods

typedef struct {

    float cash;

    float online;

} PaymentMethods;


// Function to calculate total amount

float calculateTotalAmount(PaymentMethods paymentMethods) {

    return paymentMethods.cash + paymentMethods.online;

}


int main() {

    PaymentMethods paymentMethods;

    printf("Enter the amount received in cash: ");

    scanf("%f", &paymentMethods.cash);

    printf("Enter the amount received online: ");

    scanf("%f", &paymentMethods.online);


    float totalAmount = calculateTotalAmount(paymentMethods);


    printf("\nSummary:\n");

    printf("Cash: %.2f\n", paymentMethods.cash);

    printf("Online: %.2f\n", paymentMethods.online);

    printf("Total Amount: %.2f\n", totalAmount);


    return 0;

}

```


This program demonstrates the following concepts:


1. *Payment methods structure*: A structure to represent payment methods with attributes like cash and online.

2. *Total amount calculation*: A function to calculate the total amount received based on the payment methods structure.


Note that this program is a simplified example and does not cover real-world complexities like:


- Multiple payment methods (e.g., credit/debit cards, checks)

- Payment processing fees

- Currency exchange rates

- Tax calculations


To make this program more comprehensive and useful, you would need to consider these factors and add additional features and functionality.


Example Use Cases:

- A small business owner wants to track the total amount received from customers in cash and online.

- An e-commerce platform wants to calculate the total amount received from customers through various payment methods.

- A financial institution wants to track the total amount received from customers through different payment channels.

No comments:

Post a Comment

Featured posts

What is the future of the new generation?

 What is the future of the new generation? The future of the new generation is exciting and uncertain. With rapid advancements in technology...

Popular posts