FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Basic C Programming Help?





liljp617
Quote:
Write a computer program in C which will request the user to enter a number representing the amount of foreign currency he/she would like to exchange. Your program should output a foreign currency conversion table for at least 6 different currencies, showing how much of each type of foreign currency can be obtained for the amount the user enters.

The example below shows a foreign currency exchange table for one unit of foreign currency. Your program is interactive and so should work for any input amount from the user not just 1.00. In the example table, the number entered by the user is 1, and it shows that 1 USD is equal to 0.547525 GBP, while 1 GBP is equal to 2.11928 AUD and so forth. If the user enters 2, your table should show how much 2 USD is in GBP, CAD, EUR, etc. along with how much 2 CAD would be in EUR, GBP, USD, etc, for each of the 6 currencies. The example uses real graphics not ASCII-art so it is ok if your table is not as visually pleasing.



So far this is what I've done:

Quote:

/*
Takes currency input from user and outputs currency conversions for USD, GBP, CAD,
EUR, AUD, CYN (Chinese Yuan)
*/

#include <stdio.h>
#include <stdlib.h>

main()
{

/* Declare and Initialize Variables */
const float USD = 1.0000;
const float GBP = 0.5653;
const float CAD = 1.0637;
const float EUR = 0.7006;
const float AUD = 1.2335;
const float CYN = 6.8400;
const float UserInput = '\0';

/* Begin user interaction */
printf("Please input the amount of currency you wish to convert: ");
scanf("%d", &UserInput);
printf("\n");
printf("\n");

printf("|----------------------------------------------------|\n");
printf("| | USD | GBP | CAD | EUR | AUD | CYN |\n");
printf("|----------------------------------------------------|\n");
printf("| USD | | | | | | |\n");
printf("|----------------------------------------------------|\n");
printf("| GBP | | | | | | |\n");
printf("|----------------------------------------------------|\n");
printf("| CAD | | | | | | |\n");
printf("|----------------------------------------------------|\n");
printf("| EUR | | | | | | |\n");
printf("|----------------------------------------------------|\n");
printf("| AUD | | | | | | |\n");
printf("|----------------------------------------------------|\n");
printf("| CYN | | | | | | |\n");
printf("|----------------------------------------------------|\n");

system("PAUSE");
return 0;
}



All the "|" should line up obviously to make it look like a table, but the forum formatted it oddly.

The basic gist of the program is that the user will input a currency amount (in $US) they wish to convert. After they input the currency amount, the program is supposed to output that table with all the conversions. It should output the entire table every time they put in a currency amount to convert. Inside the actual cells, should be a number going two decimal places (I'm aware it's %.2f to get that).

Anyway, I don't even know if I've done everything up to this point correctly. But if I have, my next step (I assume) would be to do the actual conversions. And I don't particularly know how to do that or what to do. Would I do the conversions within each individual cell in the table? How would I do that? Or would I do them somewhere outside of the table and store them as a variable of some sort and then input that variable into the table somehow?

If someone could give an example of how they would do the first row (USD across) or describe how they would do it, that would be great.

Any help/direction/corrections is welcome and very much needed. I know it's not hard, but this is the very first bit of programming I've ever done so...

Thanks in advance for any help at all.
a-r-t-u-r
Try this way...
Code:

/*
Takes currency input from user and outputs currency conversions for USD, GBP, CAD,
EUR, AUD, CYN (Chinese Yuan)
*/

#include <stdio.h>
#include <stdlib.h>
//ADD NEW INCLUDES FOR MY COMMAND WORK
#include <iostream>
#include <conio.h>

/* Declare and Initialize Variables */
const float USD = 1.0000;
const float GBP = 0.5653;
const float CAD = 1.0637;
const float EUR = 0.7006;
const float AUD = 1.2335;
const float CYN = 6.8400;


float Transform(float amount, int to)
{
   switch(to)
   {
   case 1:
      return amount*USD;

   case 2:
      return amount*GBP;
      //finish next case :P


   default:
      std::cout << "ERROR... WRONG PARAMETERS\n";
   }
}
int main() // !! missing "int" between "main"


   float UserInput = 0; // why const??

/* Begin user interaction */
printf("Please input the amount of currency you wish to convert: ");
scanf("%d", &UserInput);
printf("\n");
printf("\n");

printf("|----------------------------------------------------|\n");
printf("|-----| USD | GBP | CAD | EUR | AUD | CYN |\n");
printf("|----------------------------------------------------|\n");
/* DON'T KNOW HOW WORK PRINTF, SO I USE DIFFREND COMMAND */
std::cout << "| USD | " << Transform(UserInput, 1) << " | | | | | |\n";
printf("|----------------------------------------------------|\n");
printf("| GBP | | | | | | |\n");
printf("|----------------------------------------------------|\n");
printf("| CAD | | | | | | |\n");
printf("|----------------------------------------------------|\n");
printf("| EUR | | | | | | |\n");
printf("|----------------------------------------------------|\n");
printf("| AUD | | | | | | |\n");
printf("|----------------------------------------------------|\n");
printf("| CYN | | | | | | |\n");
printf("|----------------------------------------------------|\n");

system("PAUSE");
return 0;
}


I don't know some of command u used here, like "printf", "scanf".
So i replace it by that i know, but thin u have no problem to change it to that you prefer. Very Happy
Related topics
Complete Tutorial LINKS for every language
[Question] Visual Basic C++, PHP, mySQL language guides...
Programming Help & Support Guidelines
C++ assignment help
linux-windows c/c++ programming
linux windows c programming
Game Designer
Beginning Programming... Help!
Programming
Basic Socket Programming Error in Linux.. Pls help
C++ Program Basics
New endeavour: C programming language
Introduction to C++ Programming+First Program
3 Websites To Get Started With Learning C++ Programming Lan
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.