Currency Conversion in C Programming

Discussion in 'Computer Science & Culture' started by Kennesu, Mar 13, 2012.

Thread Status:
Not open for further replies.
  1. Kennesu Registered Member

    Messages:
    1
    I have an assignment where i have to converted an entered amount and convert it to US currency. when entering an amount, it has to be entered with a letter and number. for example amount has to be written as Y1000 is $11.87. i guess you can say that im having trouble knowing how to write up a code taht will allow that. can someone please help me?
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. przyk squishy Valued Senior Member

    Messages:
    3,203
    Do you at least have a partial solution already, or can you explain more specifically what you're having trouble with? The point of an assignment like this is that you learn by working out how to write the code yourself as much as possible, so obviously no sensible poster here is just going to provide a full solution for you. So if you need help you're going to have to be more specific about what you already know and what you're stuck on.

    If you literally have no idea what a C program looks like and have no idea where to start, then an internet forum like this is really the wrong medium to start learning from and your best bet is to follow an introduction to the language. (If you need it, a Google search for "C tutorial" will turn up plenty of hits.)
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. Chipz Banned Banned

    Messages:
    838
    This doesn't give you everything, but it does help demonstrate SOME of the challenges. Everything is there for you to make a usable version. Good luck!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    struct currency {
    	char prefix;
    	double conversion;
    } _G_yuan = {'Y', 4.53 },
      _G_pound= {'P', .97  };
    
    
    int 
    main(int argc, char* argv[])
    {
    	char* cpy;
    	int len;
    	len=strlen(argv[1]);
    	cpy=(char*)malloc(sizeof(char)*len);
    	strcpy(cpy, &argv[1][1]);
    	
    	printf("There are %s of me!\n",cpy);
    	
    	switch (argv[1][0])
    	{
    	case 'Y':
    		printf("I'm a yuan!\n");
    		break;
    	case 'P':
    		printf("I'm a pound!\n");	
    		break;
    
    	}
    	free(cpy);
    	return 0;
    }
    
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. Chipz Banned Banned

    Messages:
    838
    I'm guessing he'll be a one post wonder.
     
  8. Crunchy Cat F-in' *meow* baby!!! Valued Senior Member

    Messages:
    8,423
    I would agree.
     
Thread Status:
Not open for further replies.

Share This Page