Thread: Can someone help me with validating?

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    2

    Can someone help me with validating?

    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

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    2

    help with validate input errors

    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();
    
    
    }

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You cannot have nested functions in C.
    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'... */
    You can call (invoke) a function from within another function, but you do not create the contents (define) a function inside another one.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    Quote Originally Posted by quzah
    You cannot have nested functions in C.


    Yes you can have nested functions if your compiler supports it !
    -- Add Your Signature Here --

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by tjohnsson


    Yes you can have nested functions if your compiler supports it !
    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.
    If you understand what you're doing, you're not learning anything.

  6. #6
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70

    Thumbs up

    Quote Originally Posted by itsme86
    I guess you could also write your programs backwards if your compiler supported it.


    No problem, that would be nice feature and who knows maybe that becomes to standard someday...
    -- Add Your Signature Here --

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Validating unsigned integers with scanf()
    By Mr_Miguel in forum C Programming
    Replies: 7
    Last Post: 03-04-2008, 01:51 PM
  2. validating input using scanf
    By Axel in forum C Programming
    Replies: 6
    Last Post: 09-12-2005, 08:23 AM
  3. validating a date month and year format
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 08-16-2005, 07:45 AM
  4. Validating data Input
    By sql.scripter in forum C++ Programming
    Replies: 5
    Last Post: 04-23-2005, 01:56 AM
  5. validating user input
    By andrew_lillis in forum C++ Programming
    Replies: 10
    Last Post: 10-27-2002, 08:11 AM