1. Currency Conversion Program

Hi all,

I'm new here but im just interested in some input into my program. Its for a college assignemt but i have done C programming before. Im just wondering if any of you guys would do it a diffrent way?

I have the Euro to Pound section workin and the rest is simply copy and paste so im sorted. But as i said just some input and perhaps some ideas on how to do it other ways.

Code:
```#include <stdio.h>

int main()

{

#define POUND 0.70
#define KRONE 7.43
#define YEN 127

float local_amount, remote_amount;

printf("1. Britain\n");
printf("2. Denmark\n");
printf("3. Japan\n");
printf("4. USA\n");
printf("5. Exit Program\n\n");

/* Ask user for there choice */
/* And Asign the choice to varabial manu_choice, which is of int data type */

{
printf("\n\nDo you wish to convert from:\n\n");
printf("1. Euro to Pound(Sterling)\n");
printf("2. Pound(Sterling) to Euro\n\n");

{
printf("\n\nEuro to Pound(Sterling):\n\n");

printf("Please Enter Euro Amount to be Converted: \t");
scanf("%f",&local_amount);

remote_amount = local_amount * POUND;

printf("\n%f Euro is equal to %f Pound",local_amount, remote_amount);

}

{

printf("\n\nPound(Sterling) to Euro:\n\n");

printf("Please Enter Pound(Sterling) Amount to be Converted: \t");
scanf("%f",&local_amount);

remote_amount = local_amount / POUND;

printf("\n%f Pound is equal to %f Euro",local_amount, remote_amount);

}

}

{
printf("2. Denmark\n");
}

{
printf("3. Japan\n");
}

{
printf("4. USA\n");
}

{
printf("5. Thank You and Good Bye!\n");
}

return 0;

}```

2. Might look into using switch case instead of ifs.

3. >Im just wondering if any of you guys would do it a diffrent way?
>But as i said just some input and perhaps some ideas on how to do it other ways.

When this question came up once before, I tried something like this.
Code:
```#include <stdio.h>
#include <string.h>

const char Description[] =
"Currency Conversion As of June 11, 2003 2:35am GMT";

void convert(const char *from, const char *to, double amount)
{
static const struct
{
const char *name;
double rate;
} Xchg[] = /* US Dollar conversion factor */
{
{ "USD",      1.0         },
{ "Lire",     0.000603049 },
{ "Yen",      0.008464602 },
{ "Pound",    1.65123     },
{ "Peso",     0.0940910   },
};
size_t i,j;

for ( i = 0; i < sizeof(Xchg)/sizeof(*Xchg); ++i )
{
if ( strcmp(Xchg[i].name, from) == 0 )
{
for ( j = 0; j < sizeof(Xchg)/sizeof(*Xchg); ++j )
{
if ( strcmp(Xchg[j].name, to) == 0 )
{
double value = amount * Xchg[i].rate / Xchg[j].rate;
printf("%g %s = %g %s\n", amount, from, value, to);
return;
}
}
printf("Cannot convert to \"%s\"\a\n", to);
return;
}
}
printf("Cannot convert from \"%s\"\a\n", from);
}

int main(void)
{
puts(Description);
convert("USD",  "Pound",  20.0);
convert("Yen",  "Lire",  100.0);
convert("Euro", "Krone",  20.0);
convert("USD",  "Krone",  20.0);
return 0;
}

/* my output
Currency Conversion As of June 11, 2003 2:35am GMT
20 USD = 12.1122 Pound
100 Yen = 1403.63 Lire
Cannot convert from "Euro"
Cannot convert to "Krone"
*/```