-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutility.c
232 lines (206 loc) · 6.15 KB
/
utility.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*Project by:
Hamza Nizamani SE231027
Abdullah Nabi Ahmed SE231040
Jawad Nasir SE231041
*/
#include <stdio.h>
void calculate_bill();
void currency_conversion();
void estimateGroceries();
void displayGroceries(const char *groceries[], const double prices[]);
double calculateTotal(const int choices[], const double prices[], int size);
int main()
{
int choose, a = 1;
while (a == 1)
{
printf("\n**************************************WELCOME****************************************\n"
"--> Enter 1 for Bill Calculation\n"
"--> Enter 2 for Currency Conversions\n"
"--> Enter 3 to Estimate Groceries Budget\n"
"--> Enter 4 to Exit\n");
scanf("%d", &choose);
switch (choose)
{
case 1:
calculate_bill();
break;
case 2:
currency_conversion();
break;
case 3:
estimateGroceries();
break;
case 4:
printf("Exiting the program. Goodbye!\n");
a = 0;
break;
default:
printf("Invalid Entry!!\n");
break;
}
}
return 0;
}
// Bill function
void calculate_bill()
{
int choose, curr_units, prev_units, units;
float bill;
printf("\nPlease,\n");
printf("--> Enter 1 for Electricity Bill\n");
printf("--> Enter 2 for Gas Bill\n");
scanf("%d", &choose);
switch (choose)
{
case 1:
printf("Please enter number of units for this month: ");
scanf("%d", &curr_units);
printf("Please enter number of units for the previous month: ");
scanf("%d", &prev_units);
units = curr_units - prev_units;
if (units <= 200)
{
printf("Your bill for this month is Rs %.3f", bill = units * 50);
}
else if (units > 200)
{
printf("Your bill for this month is Rs %.3f", bill = units * 61);
}
break;
case 2:
printf("Please enter number of units for this month: ");
scanf("%d", &curr_units);
printf("Please enter number of units for the previous month: ");
scanf("%d", &prev_units);
units = curr_units - prev_units;
if (units <= 100)
{
printf("Your bill for this month is R.s %f", bill = units * 18);
}
else if (units > 150)
{
printf("Your bill for this month is R.s %f", bill = units * 30);
}
break;
default:
printf("Invalid Entry!!");
break;
}
}
// Currency conversion function
void currency_conversion()
{
int currency;
double amount, converted;
printf("\nSelect the currency you want to exchange:\n");
printf("1. USD to PKR\n");
printf("2. PKR to USD\n");
printf("3. DIRHAM to PKR\n");
printf("4. PKR to DIRHAM\n");
printf("5. RIYAL to PKR\n");
printf("6. PKR to RIYAL\n");
printf("7. POUND to PKR\n");
printf("8. PKR to POUND\n");
printf("9. EUR to PKR\n");
printf("10. PKR to EUR\n");
scanf("%d", ¤cy);
switch (currency)
{
case 1:
printf("Enter your amount in USD: ");
scanf("%lf", &amount);
printf("PKR = %.2lf", converted = amount * 276.91);
break;
case 2:
printf("Enter your amount in PKR: ");
scanf("%lf", &amount);
printf("USD = %.2lf", converted = amount / 276.91);
break;
case 3:
printf("Enter your amount in DIRHAMS: ");
scanf("%lf", &amount);
printf("PKR = %.2lf", converted = amount * 75.89);
break;
case 4:
printf("Enter your amount in PKR: ");
scanf("%lf", &amount);
printf("DIRHAM = %.2lf", converted = amount / 75.89);
break;
case 5:
printf("Enter your amount in RIYAL: ");
scanf("%lf", &amount);
printf("PKR = %.2lf", converted = amount * 74.32);
break;
case 6:
printf("Enter your amount in PKR: ");
scanf("%lf", &amount);
printf("RIYAL = %.2lf", converted = amount / 74.32);
break;
case 7:
printf("Enter your amount in POUND: ");
scanf("%lf", &amount);
printf("PKR = %.2lf", converted = amount * 351.99);
break;
case 8:
printf("Enter your amount in PKR: ");
scanf("%lf", &amount);
printf("POUND = %.2lf", converted = amount / 351.99);
break;
case 9:
printf("Enter your amount in EUR: ");
scanf("%lf", &amount);
printf("PKR = %.2lf", converted = amount * 304.41);
break;
case 10:
printf("Enter your amount in PKR: ");
scanf("%lf", &amount);
printf("EUR = %.2lf", converted = amount / 304.41);
break;
default:
printf("SELECT A VALID CURRENCY!!\n");
break;
}
}
// Groceries function
void estimateGroceries()
{
const char *groceries[8] = {"Bread", "Milk(1L)", "Eggs(1 Dozen)", "Cheese", "Cooking Oil(1L)", "Rice(5kg)", "Sugar(1kg)", "Salt(1kg)"};
const double prices[8] = {120.50, 180.20, 320.80, 3000.50, 2400.87, 1800.85, 180.00, 200.00};
int userChoices[8] = {0};
int choice;
double totalAmount = 0;
do
{
displayGroceries(groceries, prices);
printf("\nEnter the number of the grocery to add to your basket (0 to finish): ");
scanf("%d", &choice);
if (choice >= 1 && choice <= 8)
{
userChoices[choice - 1]++;
totalAmount += prices[choice - 1];
}
else if (choice != 0)
{
printf("Invalid choice. Please enter a number between 1 and %d.\n", 8);
}
} while (choice != 0);
printf("\nYour Choices:\n");
for (int i = 0; i < 8; i++)
{
if (userChoices[i] > 0)
{
printf("%-15s - Quantity: %d\n", groceries[i], userChoices[i]);
}
}
printf("\nYour Estimated Grocery Budget is: Rs %.2f\n", totalAmount);
}
// For displaying groceries function
void displayGroceries(const char *groceries[], const double prices[])
{
printf("\nList of items:\n");
for (int i = 0; i < 8; i++)
{
printf("%d. %-15s \t- Rs %.2f\n", i + 1, groceries[i], prices[i]);
}
}