-
Notifications
You must be signed in to change notification settings - Fork 1
/
6.c
169 lines (168 loc) · 3.7 KB
/
6.c
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include<stdio.h>
int digit(char num[])
{
int i=0,flag=0;
while(num[i]!='\0')
{
if(num[i]>=48&&num[i]<=57)
flag=1;
else
{
flag=0;
break;
}
i++;
}
return flag;
}
int alphanum(char num[])
{
int i=0,flag=0;
while(num[i]!='\0')
{
if((num[i]>=48&&num[i]<=57)||((num[i]>=65&&num[i]<=91)||(num[i]>=97&&num[i]<123)))
flag=1;
else
{
flag=0;
break;
}
i++;
}
return flag;
}
int alpha(char name[])
{
int i=0,flag=0;
while(name[i]!='\0')
{
if((name[i]>=65&&name[i]<=90)||(name[i]>=97&&name[i]<122))
flag=1;
else
{
flag=0;
break;
}
i++;
}
return flag;
}
int call_by_ref(int *y) {
int temp;
printf("Enter the new Quantity\n");
scanf("%d",&temp );
*y =temp;
}
int call_by_val(int x){
int temp_amt,temp_rate;
printf("In case if you want to check the price for a different quantity enter the quantity\n");
scanf("%d",&x );
printf("Enter the rate\n");
scanf("%d",&temp_rate );
temp_amt=temp_rate*x;
printf("The amount will be %d\n",temp_amt );
}
int pass(char purchase[]){
int amt,qty,rate;
char tab[30];
printf("Enter the tablet name\n");
scanf("%s",tab );
printf("Enter the Quantity\n");
scanf("%d",&qty );
printf("Enter the rate\n");
scanf("%d",&rate );
amt=qty*rate;
printf("The total amount for %s %s is %d\n", purchase,tab,amt);
}
int recursion(int counter){
int qty;
char name[20];
if(counter>0){
printf("enter the name\n" );
scanf("%s",name );
if(strcmp(name,"dasa")==0){
printf("Sorry you have been banned from purchasing tabs from any of our stores.Please pay your dues first or get lost\n" );
}
else{
printf("Enter the quantity\n" );
scanf("%d",&qty );
printf("%s has bought %d quantities of tablet\n",name,qty );
}
}
else{
return 0;
}
counter --;
recursion(counter);
}
int main() {
int ch,amt,qty,rate,validnum,validname,counter;
char name[30],tab[30],no[30],purchase[20];
a:printf("1.Edit the Bill\n2.View the bill\n3.Know what he has purchased\n4.Look at the available counters\n5.exit\n" );
printf("Enter the choice\n");
scanf("%d",&ch );
switch (ch) {
case 1:
printf("Enter the bill No.\n");
scanf("%s",no);
validnum=digit(no);
if(validnum==0){
printf("\nInvalid Input.Please enter only numeric value \n");
}
else{
printf("Enter the name\n" );
scanf("%s",name );
validname=alpha(name);
if(validname==0){
printf("Invalid Input..Enter only characters\n" );
}
else{
printf("Enter the tablet name\n");
scanf("%s",tab );
printf("Enter the Quantity\n");
scanf("%d",&qty );
printf("Enter the rate\n");
scanf("%d",&rate );
amt=qty*rate;
printf("The total amount it %d\n", amt);
call_by_ref(&qty);
printf("The new Quantity has been updated to %d \n", qty);
amt=qty*rate;
printf("The updated bill amount for %s is %d\n",tab,amt );
}
}
goto a;
break;
case 2:
printf("Enter the bill No.\n");
scanf("%s",no );
printf("Enter the name\n" );
scanf("%s",name );
printf("Enter the tablet name\n");
scanf("%s",tab );
printf("Enter the Quantity\n");
scanf("%d",&qty );
printf("Enter the rate\n");
scanf("%d",&rate );
amt=qty*rate;
printf("The total amount is %d\n", amt);
call_by_val(qty);
printf("But collect only %d\n",amt );
goto a;
break;
case 3:
printf("What has he purchased\n");
scanf("%s",purchase);
pass(purchase);
goto a;
break;
case 4:
printf("Enter the available counters\n" );
scanf("%d",&counter );
recursion(counter);
goto a;
break;
case 5:
break;
}
}