Hi. This program worked until I tried inserting the validation code. I keep getting parse errors. Can someone tell me where I am messing up? First, I ned to know how to post code
Thanks.
Maria Jordan
Hi. This program worked until I tried inserting the validation code. I keep getting parse errors. Can someone tell me where I am messing up? First, I ned to know how to post code
Thanks.
Maria Jordan
Code:Can someone tell me where my errors are in the validate Input part of the following code? I keep getting Parse errors. The program ran fine before I inserted the lines about validating input. Thank you so much. Maria Joran #include <stdio.h> main () { //Declare Variables float USD, BP, CASH, CONVERTCURRENCY; int validateInput(float BP) { // when the condition is true ouput the contents of "" on screen if ((BP < 0.0001) || (BP > 1000000.0)) { printf("\nUSER INPUT ERROR: Invalid Amount\n"); // return 0 to the calling function return 0; } // when the condition is false returns 1 else return 1; } //Initialize the Variables USD = 1; // US Dollar BP = USD/0.5350; // British Pound Exchange Rate //Print Conversion printf("Convert Currency\n\n"); // Prints Header "Convert Currency" printf(" USD = %.2f\n", USD); // Prints US Dollars printf(" BP = %.2f\n", BP); // Prints British Pound Conversion to US Dollars //User Input printf("Convert one currency to another.\n\n"); printf("Enter the amount of British Pounds you would like to be converted to US dollars.\n\n"); scanf("%f", &CASH); CONVERTCURRENCY=BP*CASH; //This number will represent the amount in US Dollars. printf("The amount you entered equals $%.2f in US Dollars.\n\n", CONVERTCURRENCY); return 0; printf("Press any key to continue...\n"); getch(); printf("Press any key to continue...\n"); getch(); }
You cannot have nested functions in C.
You can call (invoke) a function from within another function, but you do not create the contents (define) a function inside another one.Code:#include <stdio.h> main () { /* Declare a function, 'main', and define the body of it... */ //Declare Variables float USD, BP, CASH, CONVERTCURRENCY; int validateInput(float BP) { /* Inside main, try declaring another function 'validateInput'... */
Quzah.
Hope is the first step on the road to disappointment.
Originally Posted by quzah
![]()
Yes you can have nested functions if your compiler supports it !
-- Add Your Signature Here --
I guess you could also write your programs backwards if your compiler supported it. When someone on this forum says "you can't do <x> in C" they mean in standard C.Originally Posted by tjohnsson
If you understand what you're doing, you're not learning anything.
Originally Posted by itsme86
![]()
No problem, that would be nice feature and who knows maybe that becomes to standard someday...
-- Add Your Signature Here --