A simple currency conversion program gone south!!

This is a discussion on A simple currency conversion program gone south!! within the C Programming forums, part of the General Programming Boards category; I am working on this conversion program that I have pieced together off the web as this is my first ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    1

    A simple currency conversion program gone south!!

    I am working on this conversion program that I have pieced together off the web as this is my first experience in programming in C. The concept of the program will eventually be converting foreign currency to U.S. dollars. As of now, I can convert the first amount (Pesos), however cannot convert the 2nd amount (Euros). I think there is an error in the first printf line that separates the two different currency amounts.

    Any help would be appreciated.
    Thanks.

    Code:
    #include <stdio.h>
    
    void print_converted(int dollars)
    /* Converts from foreign country to U.S. currency*/
    {	float dollars1 = dollars / (14.247);
    	float dollars2 = dollars / (0.7585);
    	
    	printf("%5.2f\n",dollars1, dollars2);
    	}
    	
    	main()
    	
    	{	
    	
    	int us_peso,us_euro;
    	printf("Currency Conversion by RH v1.1\n\n\n"); /*Title */
    	printf("One U.S. Dollar = 14.247 Mexico Peso\n"); /*Prints currency for Mexico*/
          printf("One U.S. Dollar = 0.7585 Euro\n");  /*Prints currency for countries that use the Euro*/
          printf("One U.S. Dollar = 89.104 Japan Yen\n");/*Prints currency for Japan*/
          printf("One U.S. Dollar = 0.7059 UK Pound\n");/*Prints currency for the United" Kingdom*/
          printf("One U.S. Dollar = 173.50 Djibouti Franc\n\n\n");/*Prints currency for Djibouti (My current location)*/
    	printf("Give me a foreign currency amount  : ");
    	
    		 if (scanf("%d", &us_peso)!=1)
    		printf("Wrong!! You entered a character, please try again\n"); /* Error checker for a character */
    		else 
    		{
    		 if (us_peso<0)
    	printf("Wrong!! You entered a negetive number, please try again\n"); /* Error checker for a negetive number */
    		else	 {
    		
    				
    					
    	printf("\nThank you!!\n\n");
    	printf("(Your %d Mexican Pesos) ", us_peso), printf(" ---->  (U.S. Dollars) = $"),print_converted(us_peso); /*Prints conversion to US dollars */
    	printf("(Your %d Euros) ",us_peso), printf(" ------------>  (U.S. Dollars) = $"),print_converted(us_euro); /*Prints conversion to US dollars */
    
    		     	 }  
    		
    		}	
    	
    	}
    /*	1.1 Currency Conversion, RH, 1/31/09; added the prompt for inputing amount*/
    /*	1.0 Currency Conversion, RH, 1/28/09; initial version*/

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    printf("%5.2f\n",dollars1, dollars2);

    should be
    Code:
    printf("%5.2f %5.2f\n",dollars1, dollars2);
    main()

    should be
    Code:
    int main(void)
    read FAQ


    you never calculate your us_euro value

    I think you should devide your code so the input, calculations and output will be in different function to easier see the program logic

    currently you have a mix that is hard to understand
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Builder C++ large files support for simple C program
    By Murfury in forum C Programming
    Replies: 3
    Last Post: 11-23-2007, 02:47 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Need help with simple, simple program.
    By LightsOut06 in forum C Programming
    Replies: 5
    Last Post: 09-01-2005, 08:31 PM
  4. Problem with simple XOR program
    By spike_ in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2005, 12:09 AM
  5. Help with variables (newbee)
    By stugatza in forum C Programming
    Replies: 7
    Last Post: 08-18-2004, 10:40 AM

Tags for this Thread


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