GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 31-Jan-2005, 07:20
JYGUTI JYGUTI is offline
New Member
 
Join Date: Jan 2005
Posts: 3
JYGUTI is on a distinguished road
Question

C++ Beginner


I am trying to convert USD to a couple of foreign currency and I am not sure how write this calculation. Can someone help me? Thanks in advance.
  #2  
Old 31-Jan-2005, 10:33
number7 number7 is offline
New Member
 
Join Date: Dec 2004
Location: Virtual City, Neural Networks str. 7
Posts: 25
number7 is on a distinguished road
CPP / C++ / C Code:
float fUSDValue;

float afRates[] = {
1.00,   // USD
2.3 // EUR
4.2 // GB
// . . 
// to nCurrenciesCount
};

for (int i=0; i<nCurrenciesCount;i++) {
  fRate = fUSD * afRates[i];
}
That's the one of the basic ideas. :-D
__________________
You are the winner !

http://www.merchantsreviews.com
http://www.mindsocean.com
http://www.algirdas.com
Last edited by LuciWiz : 01-Feb-2005 at 15:13. Reason: Please insert your C code between [c] & [/c] tags
  #3  
Old 31-Jan-2005, 14:13
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by JYGUTI
I am trying to convert USD to a couple of foreign currency and I am not sure how write this calculation. Can someone help me? Thanks in advance.

In general, the calculation can be expressed in words as something like:

(Number of EUR) = (Number of USD) * (Number of EUR)/(Number of USD)

Now the quantity (Number of EUR)/(Number of USD) is obtained from a currency exchange table (you can find them on the web).

Programmatically:

CPP / C++ / C Code:
#include <stdio.h>

int main()
{
  char buffer[BUFSIZ];
  double EUR_per_USD = 1.3049; /* January 31, 2005, 1304 PST */

  double Number_of_Dollars;
  double Number_of_Euros;

  printf ("Enter the number of US Dollars to convert: ");
  if (!fgets(buffer, BUFSIZ, stdin)) {
    printf("Input error\n");
    return 1;
  }

  if (sscanf(buffer, "%lf", &Number_of_Dollars) != 1) {
    printf("Illegal input\n");
    return 1;
  }

  Number_of_Euros = Number_of_Dollars * EUR_per_USD;

  printf("\n\nThe number of Euros for %.2f US Dollars is %.2f\n", 
          Number_of_Dollars, Number_of_Euros);
  return 0;
}

Regards,

Dave
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 3) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Beginner JYGUTI C++ Forum 2 01-Feb-2005 12:27
Beginner to VB.NET and C#.NET theduke1997 .NET Forum 4 21-Dec-2004 18:14
Help a beginner with apache pls... seta21 Apache Web Server Forum 3 27-Nov-2004 08:27
RAID 0 -- beginner questions, need recommendation ldriskell Computer Hardware Forum 2 09-Jul-2004 19:47
Apache 1.3.28 >XP > Complete Beginner setting alias? thinnk Apache Web Server Forum 2 26-Mar-2004 00:42

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:13.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.