C program on calculating the amount with tax using assignment operator

In C programming, calculating tax on an amount is a common application of arithmetic and assignment operators. This program demonstrates how to compute the total amount by adding a specific tax percentage to the original amount.

Syntax

total_amount = original_amount + (original_amount * tax_rate);

Problem

Write a C Program to enter the amount in dollars and then display the amount by adding 18% as tax.

Solution

Let's consider the restaurant person adding 18% tax to every bill of the customer.

The logic applied to calculate tax is −

value = (money + (money * 0.18));

The money should be multiplied by 18% and added to the money, then the restaurant person can receive the amount from a customer with tax.

Example 1: Calculating 18% Tax

#include <stdio.h>

int main() {
    float money, value;
    printf("Enter the amount in dollars: ");
    scanf("%f", &money);
    value = (money + (money * 0.18));
    printf("Amount after adding 18%% tax: $%.2f
", value); return 0; }
Enter the amount in dollars: 250
Amount after adding 18% tax: $295.00

Example 2: Calculating 20% Tax

Let us consider the same program by changing the tax percentage to 20% −

#include <stdio.h>

int main() {
    float money, value;
    printf("Enter the amount in dollars: ");
    scanf("%f", &money);
    value = (money + (money * 0.20));
    printf("Amount after adding 20%% tax: $%.2f
", value); return 0; }
Enter the amount in dollars: 250
Amount after adding 20% tax: $300.00

Key Points

  • The assignment operator = stores the calculated result in the variable.
  • Tax calculation formula: total = amount + (amount × tax_rate)
  • Use %.2f to display monetary values with 2 decimal places.
  • The %% in printf displays a literal percent symbol.

Conclusion

This program demonstrates basic arithmetic operations and assignment operators to calculate tax on an amount. The formula can be easily modified for different tax rates by changing the multiplication factor.

Updated on: 2026-03-15T13:39:05+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements