Explanation
This code is a program written in C programming language that calculates the actual bill under
certain conditions.
The header file stdio.h
is included for using the standard input and output functions
in the code.
The main logic of the code is defined in the main()
function. The variables
d
,
m
, and j
are declared and initialized with the values of 0, 0 and the bill
amount
respectively. The program first prints a brief description of the conditions under which the bill
will be
calculated.
The program then asks the user to enter the bill amount which is stored in the d
variable. The code then
checks whether the bill amount is greater than 1000 or not. If it is, then a discount of 10% is
given and the value
of m
is set to 10. If it is not, then no discount is given and the value of
m
remains 0.
The actual bill amount is then calculated by subtracting the discount from the original bill amount.
The calculated
bill is then displayed using the printf()
function. The program finally returns 0 to
indicate the
successful execution of the code.
Code
/*
* -----------------------------------------------------------
* Logic Building with Computer Programming (CSU1128)
* Instructor: Dr. Pankaj Vaidya | Author: Divya Mohan
*
* This code is a part of the educational initiative by dmj.one
* with aim of empowering and inspiring learners in the field of
* Computer Science and Engineering through the respective courses.
*
* (c) 2022, Divya Mohan for dmj.one. All rights reserved.
* -----------------------------------------------------------
*/
#include <stdio.h>
int main()
{
float d, m = 0, j;
printf("\n\n Program to calculate the actual bill under conditions that:");
char o[10][10] = {"%"};
printf("\n\t - if the bill amount is greater than Rs 1000/- then a discount of 10%s will be given.", o[0]);
printf("\n\t - else no discount will be given. Display the total bill. \n\n");
printf("Enter the bill amount - (Example: 2336) - and press enter: ");
scanf("%f", &d);
if (d > 1000)
{
m = 10;
}
j = d - d * m / 100;
printf("\n Total bill is %.2f \n", j);
return 0;
}
Output
Program to calculate the actual bill under conditions that:
- if the bill amount is greater than Rs 1000/- then a discount of 10% will be given.
- else no discount will be given. Display the total bill.
Enter the bill amount - (Example: 2336) - and press enter: 4332
Total bill is 3898.80