Original Post
Hi Guys, I am pretty new at programming and I have been trying to write a program with functions to be used for currency exchange. When I wrote it without the functions it worked fine but I am finding it a bit hard to implement functions correctly. Below is the script:
Quote:This is what is displayed when I try to compile it:
/*This program will convert Currencies*/ #include float exchangerate(float rate) { return r; } float euroconversion(float P) { return r*P; } float poundconversion(float E) { return (E/r); } int main(void) { float r,P,E,X1,X2; int menu; printf("Currency Conversion Program\n"); printf("-------- ---------- -------\n"); printf(" Enter the euro exchange rate for 1 pound:\n"); scanf("%f",&r); printf("Menu\n"); printf("1= Convert Pounds to Euros\n"); printf("2= Convert Euros to Pounds\n"); printf("3= Exit\n"); printf("Choose any of the above choices\n");/*Asks the user to choose one of the menu options*/ scanf("%d", &menu); switch (menu) { case 1: { printf("Choice: 1\n"); printf("Enter your currency in pounds:\n"); scanf("%f",&P); X1= euroconversion(r); /*Formula converts pounds to Euros*/ printf("%.2f pounds = %.2f euros today\n",P,X1); break; } case 2: { printf("Choice: 2\n"); printf("Enter your currency in euros:\n"); scanf("%f",&E); X2= poundconversion(r); /*Formula converts Euros to Pounds*/ printf("%.2f euros = %.2f pounds today\n",E,X2); break; } case 3: { printf("You have chosen to Exit\n"); break ;/*The Program Ends!*/ } } return 0; }
Quote:Thanks in advance for your help.
1>------ Build started: Project: Lab 5 part A, Configuration: Debug Win32 ------ 1>Compiling... 1>CURRENCYEXCHANGE.c 1>c:\users\rodney\documents\visual studio 2005\projects\lab 5 part a\lab 5 part a\currencyexchange.c(8) : error C2065: 'r' : undeclared identifier 1>c:\users\rodney\documents\visual studio 2005\projects\lab 5 part a\lab 5 part a\currencyexchange.c(8) : warning C4244: 'return' : conversion from 'int' to 'float', possible loss of data 1>Build log was saved at "file://c:\Users\Rodney\Documents\Visual Studio 2005\Projects\Lab 5 part A\Lab 5 part A\Debug\BuildLog.htm" 1>Lab 5 part A - 1 error(s), 1 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========