Compiler Issues

This is a discussion on Compiler Issues within the C Programming forums, part of the General Programming Boards category; I have tried to compile. Need for project. It is supposed to provide error message, but just sits there. Does ...

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

    Compiler Issues

    I have tried to compile. Need for project. It is supposed to provide error message, but just sits there. Does anyone see what the problem is?
    Code:
    /*Library for program functions*/
    #include <stdio.h>
    
    	/* This declares the atoffunction*/
    double atof(char *);
    
    	/*Main Function*/
    int main (void)
    {
    	
    	/*Declaration of Currency Conversions*/
    	int choice;
    	float money;
    	float total;
            char ch;
    	char input[10];
    	int idx, decimal_found ;
    
    
    	/*Declaration of conversion rates retrieved October 6,2005 on http://www.xe.com/ucc/ and Print*/
    	printf("\n\nCURRENCY CONVERSION\n");
    	printf("1. British Pound 0.56767=1 U.S. Dollar\n");
    	printf("2. Euro 0.83598 =1 U.S. Dollar\n");
    	printf("3. Japanese Yen 114.000=1 U.S. Dollar\n");
    	printf("4. Mexican Peso 10.71900=1 U.S. Dollar\n");
    	printf("5. Russian Ruble 28.56000=1 U.S. Dollar\n");
    	printf("Enter the number for the currency to convert...");
    
    	/*Prompt user for Type of Currency */
    	printf("\n\n Please Select the Currency you would like to convert (1-5): ");
    	scanf("%d",&choice);
    	fflush(stdin);
    	
    	
    {	
    
                char ch;
    	char input[10];
    	int idx, decimal_found ;
    
    	}
    	printf("\n\n Please enter a dollar amount you would like to convert. (US Dollars): ");
    	scanf("%f",&money);
    	
    	decimal_found = 0 ;
    
    	/*Checks for validity of input entered by user for numerical value,retreived from Aruna Pandey*/
     	for (idx = 0 ; idx < strlen(input) ; idx++)
            {
                if (input[idx] == '.')
                {
                    // check if more than one decimal character has been entered?
                    // if the decimal character was found earlier, the "decimal_found" 
                    // flag will be equal to 1. At this time, this is an invalid entry.
                    // so exit immediately.
                    //
                    if (decimal_found == 1)
                        break ;
                    else
                        decimal_found = 1 ;
                }
                else
                {
                    if (input[idx] < 48 || input[idx] > 57)
                        break ;
                }
     
             }
    	/*Checks for non numeric character*/
            if (idx < strlen(input))  
            {
    	/*Prints response for invalid entry*/
                printf("Invalid Entry. Please Try Again.\n");
            }
            else
            {
                /* converts user input to a float value*/
                &money = atof(input); 
               
    
    	/*Returns Selected Choice with Currency Conversion*/
             }
    	if(choice == 1)
    	{
    		total = money * 0.56767;
    		printf("\n\nYou will have %f British Pounds \n\n", total);
    	}
    	if(choice == 2)
    	{
    		total = money * 0.83598;
    		printf("\n\nYou will have %f Euro \n\n", total);
    	}
    	if(choice == 3)
    	{
    		total = money * 114.000;
    		printf("\n\nYou will have %f Japansese Yen \n\n",total);
    	}
    	if(choice == 4)
    	{
    		total = money * 10.71900;
    		printf("\n\nYou will have %f Mexican Pesos \n\n", total);
    	}
    	if(choice == 5)
    	{
    		total = money * 28.56000;
    		printf("\n\nYou will have %f Russian Ruble \n\n", total);
    	}
    
    	getchar();
    
    	/*normal program end*/
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    your compiler should have produced a few syntax errors. never attempt to run a program that cannot be compiled without errors. If your compiler did not produce any errors, then you need to get a different compiler or increase its error/warning levels.

    example
    Code:
     &money = atof(input);
    The above makes no sense at all and most (if not all) c compilers should complain bitterly to you.
    Last edited by Ancient Dragon; 10-21-2005 at 11:46 AM.

  3. #3
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    Code:
    fflush(stdin);
    read faq.
    Code:
    {	
    
                char ch;
    	char input[10];
    	int idx, decimal_found ;
    
    	}
    why You have defined variables again in block.

    Code:
    for (idx = 0 ; idx < strlen(input) ; idx++)
    Have you initialized variable-input before.
    Long time no C. I need to learn the language again.
    Help a man when he is in trouble and he will remember you when he is in trouble again.
    You learn in life when you lose.
    Complex problems have simple, easy to understand wrong answers.
    "A ship in the harbour is safe, but that's not what ships are built
    for"

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You don't need this:
    Code:
    double atof(char *);
    http://www.cplusplus.com/ref/cstdlib/atof.html

    [edit] And besides, it's
    Code:
    double  atof ( const char * string );
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    2
    Quote Originally Posted by Ancient Dragon
    your compiler should have produced a few syntax errors. never attempt to run a program that cannot be compiled without errors. If your compiler did not produce any errors, then you need to get a different compiler or increase its error/warning levels.

    example
    Code:
     &money = atof(input);
    The above makes no sense at all and most (if not all) c compilers should complain bitterly to you.

    The compiler is producing error
    &money should be the input?

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by marliwht
    The compiler is producing error
    &money should be the input?
    remove the & symbol from money.
    Code:
    money = ...

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    if (input[idx] < 48 || input[idx] > 57)
    I find '0' clearer than 48.

    Code:
    {	// this whole code block is useless
    
                char ch;
    	char input[10];
    	int idx, decimal_found ;
    
    	}
    	printf("\n\n Please enter a dollar amount you would like to convert. (US Dollars): ");
    	scanf("%f",&money);
    
        // somewhere in here you should actually read something into input
    	
    	decimal_found = 0 ;
    
    	/*Checks for validity of input entered by user for numerical value,retreived from Aruna Pandey*/
     	for (idx = 0 ; idx < strlen(input) ; idx++)  // input is not initialized!
            {
                if (input[idx] == '.')
                {
    And, as someone mentioned, get rid of the fflush(stdin).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler questions
    By DvdHeijden in forum C++ Programming
    Replies: 6
    Last Post: 01-17-2005, 02:00 PM
  2. Compiler issues
    By Strix Varia in forum C++ Programming
    Replies: 3
    Last Post: 01-14-2005, 01:58 AM
  3. Have you ever written a compiler?
    By ammar in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 12-27-2004, 06:10 AM
  4. C Compiler
    By SAMSEIED in forum C Programming
    Replies: 5
    Last Post: 06-06-2002, 05:44 PM
  5. Special Compiler for win app's
    By Unregistered in forum Windows Programming
    Replies: 19
    Last Post: 04-26-2002, 03:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21