-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path42th_program.c
More file actions
54 lines (53 loc) · 1.5 KB
/
Copy path42th_program.c
File metadata and controls
54 lines (53 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Write a program that uses pointer as a function argument.
// Program: Discount Calculator
// Description: Calculates the total amount and applies discounts based on the total purchase.
// Discounts are 5% for purchases between 1000 and 5000 rupees, and 8% for purchases above 5000 rupees.
#include<stdio.h>
void finalprice(float *a,int b);
int main()
{
int no_of_iteam;
float totalprice=0.0,finalpay=0.0;
printf("\n");
printf("Discount available : 5 percent on purchasing of 1000 rupees and 8 percent on above 5000 rupees \n\n");
printf("Enter no of iteam you have purchased : ");
scanf("%d",&no_of_iteam);
if(no_of_iteam<1)
{
printf("Enter valid no of iteams \n");
printf("Enter no of iteam you have purchased \n");
scanf("%d",&no_of_iteam);
}
float price[no_of_iteam];
for(int i=0;i<no_of_iteam;i++)
{
printf("Enter price of iteam %d :",i+1);
scanf("%f",&price[i]);
if(price[i]<0)
{
printf("Enter valid price \n");
printf("Ener price of item %d :",i+1);
scanf("%f",&price[i]);
}
totalprice+=price[i];
}
finalprice(&finalpay,totalprice);
printf("Total amout :%.1f \n",totalprice);
printf("After discount :%.1f \n",finalpay);
return 0;
}
void finalprice(float *a, int b)
{
if(b>=1000 && b<=5000)
{
*a=b-(b*5/100);
}
else if(b>5000)
{
*a=b-(b*8/100);
}
else
{
*a=b;
}
}