forked from Anish-1507/Computer-Project-2nd-Semester
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_updated
More file actions
152 lines (141 loc) · 5.03 KB
/
test_updated
File metadata and controls
152 lines (141 loc) · 5.03 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
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
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define len 10
int from_c,to_c,enteredAmount;
char curr[][len] = {"INR", "AUS", "SGP", "EURO", "POUND", "USD"}; ///I've still kept the array in here for future reference
float rates_to_comm [len] = {72.812, 1.289, 1.40, 0.813, 0.705, 1.00};
char new_curr[][len];
float custom_conv;
///SOME FEATURES WE CAN FURTHER IMPLEMENT
///[DONE]A function to convert from one currency
///A function to add a new currency and its rate
///A function to delete a type of currency
///A base convertor function
///A soon as a user enters the currency value we convert it to a base value and then we navigate the program using that base value
///[DONE]I say we store the currencies in a linked list
///Makes adding and deleting easier
///we declared entered data as global can be accessed from anywhere
void display()
{
}
struct currency
{
char name[40];
float rate;
struct currency*next;
};
typedef struct currency c1;
void list(){ ///Just to store the list for now, can be removed later
c1*s;
s = (c1*)malloc(sizeof(c1));
s->name[40] = "INR";
s->rate = 72.812;
s->next = (c1*)malloc(sizeof(c1));
s->next->name[40] = "AUS";
s->next->rate = 1.289;
s->next->next = (c1*)malloc(sizeof(c1));
s->next->next->name[40] = "SGP";
s->next->next->rate = 1.40;
s->next->next->next = (c1*)malloc(sizeof(c1));
s->next->next->next->name[40] = "SGP";
s->next->next->next->rate = 1.40;
s->next->next->next->next = (c1*)malloc(sizeof(c1));
s->next->next->next->next->name[40] = "SGP";
s->next->next->next->next->rate = 0.813;
s->next->next->next->next->next = (c1*)malloc(sizeof(c1));
s->next->next->next->next->next->name[40] = "POUND";
s->next->next->next->next->next->rate = 0.705;
s->next->next->next->next->next->next = (c1*)malloc(sizeof(c1));
s->next->next->next->next->next->next->name[40] = "USD";
s->next->next->next->next->next->next->rate = 1.000;
}
void info()
{
int choice;
bool flag=true;
while(flag)
{
printf("Enter the action you want to perform: \n");
printf("1. Compare currencies:\n");
printf("2. Add a new currency to existing list:\n");
printf("3. Delete a currency from the given list:\n");
printf("4. Display list of currencies available: \n");
printf("5. Exit function:");
switch(choice)
{
case 1:
///DISPLAY LIST OF AVAILABLE CURRENCIES
////CALL COMPARE CURRENCY FUNCTION
///currency compare function returns a float value
///it takes in 3 parameters
///a character array which is the currency entered
//the amount in the currency entered
///another character array which is the currency to be converted into
float from_v, to_v;
char from_c[100], to_c[100];
printf("Enter the currency you would like to convert : ");
gets(from_c);
printf("\nEnter the currency you would like to convert to: ");
gets(to_c);
printf("\nEnter the amount of money you have right now : ");
scanf("\n%f", &from_v);
to_v = cur_conv(from_v, from_c, to_c);
printf("\nThe amount in %s is %f", to_c, to_v);
break;
case 2:
////Call add currency function and add to a linked list
printf("STILL UNDER CONSTRUCTION\n");
break;
case 3:
////Call delete currency function and delete from list
printf("STILL UNDER CONSTRUCTION\n");
break;
case 4:
////Call display currency function
printf("STILL UNDER CONSTRUCTION\n");
break;
case 5:
flag=false;
}
printf("Thankyou for using currency convertor :");
}
}
void converter(struct currency c)
{
}
float cur_conv(float from_value, char from_curr[], char to_curr[])
{
float from_rate, to_rate, fin, common;
for(int i = 0;i < len; i++)
{
if(strcmp(from_curr, curr[i]) == 0){
from_rate = rates_to_comm[i];
}
}
for(int j = 0;j<len;j++){
if(strcmp(to_curr, curr[j]) == 0)
{
to_rate = rates_to_comm[j];
}
}
printf("\n %f %f", from_rate, to_rate);
common = from_value/from_rate;
printf("\n%f", common);
fin = common*to_rate;
printf("\n%f", fin);
return fin;
}
void add_currency(){
printf("Please enter the short form of the currency you would like to enter : ");
scanf("%s", &new_curr);
printf("\nPlease enter the rate with respect to USD : ");
scanf("%f",&custom_conv);
c1*s;
s->next->next->next->next->next->next->next = (c1*)malloc(sizeof(c1));
s->next->next->next->next->next->next->next->name[40] = new_curr;
s->next->next->next->next->next->next->next->rate = custom_conv;
}
int main(void)
{
}