Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

// Help me Count my Money! ! !

ljsljs Member Posts: 3
[b][red]This message was edited by ljs at 2002-10-29 11:32:48[/red][/b][hr]
Im trying to program a money counting fuction in C++, but I can't figure out how to do it. I want it to count long integers using this range: 5 - 1,000,000. Any ideas? (no floats or doubles) Just bills like 5,10,15,20-50,55-80, you know! Im a beginner programmer, please help.

long maximumCash=1000000;
long minimumCash=5;

How much math am I needed?


Comments

  • brycebryce Member Posts: 25
    [b][red]This message was edited by bryce at 2002-10-25 8:27:36[/red][/b][hr]
    [b][red]This message was edited by bryce at 2002-10-25 8:2:12[/red][/b][hr]
    : Im tring to program a money counting fuction in C++, but I can't figure out how to do it. I want it to count in integers using this range: 5 - 30,000. Any ideas? The program is for a game that Im creating, My game is pretty sweet!
    :

    Try this. It is easy to understand. I wrote it years ago in procedural
    C. It converts global currencies.

    Bryce

    //Bryce Sawin currency program.

    #include
    #include //For console freezing with borland
    //Take out for other compilers along with
    //getch(); replace with cin.get();
    #include
    #include
    #include ;
    # include ;

    using namespace std;

    //Currency rates set as global constants for calculations.
    const float French_Franks = 7.1153;
    const float Italian_Lira = 2100.3040;
    const float Japanese_Yen = 116.0650;
    const float German_Marks = 2.1215;
    const float Euros = 1.847;
    const float British_Pounds = 0.6908;
    const float Canadian_Dollars = 1.5339;
    const float Australian_Dollars = 1.8859;
    const float US_Dollars = 1.0;

    //Function prototypes.
    void DisplayCurrency(void);
    int GetCurrencySelection(int&);
    bool IsCurrencySelectionValid(int currencySelection);
    double CalcExchangeAmount(double&, int currencySelection);
    void DisplayResults(int currencySelection, double exchangeAmount,
    double dollarAmount);

    //Global variable for main input
    double dollar;

    //Start Main
    int main(int argc, char **argv)
    {

    //Return parameters declared for function calls.
    auto int return1;
    auto double return2;
    char inChar;

    do
    {
    cout << "Please enter the total dollar amount to exchange: $";
    cin >> dollar;
    cout << "Please select a target currency:

    ";

    //Functions called.
    DisplayCurrency();
    GetCurrencySelection(return1);
    CalcExchangeAmount(return2, return1);
    IsCurrencySelectionValid(return1);
    DisplayResults(return1, return2, return2);

    //Prompt to continue with do while loop.
    cout << "
    Do you wish to continue? (Y for yes - N for no).";
    cin >> inChar;
    }while((inChar == 'Y')||(inChar == 'y'));

    exit(1);
    getch();
    return 0;
    }

    //Function to display currencies.
    void DisplayCurrency(void)
    {
    cout << " " << "(1) French Francs";
    cout << "
    " << " " << "(2) Italian Lira";
    cout << "
    " << " " << "(3) Japanese Yen";
    cout << "
    " << " " << "(4) German Marks";
    cout << "
    " << " " << "(5) Euros";
    cout << "
    " << " " << "(6) British Pounds";
    cout << "
    " << " " << "(7) Canadian Dollars";
    cout << "
    " << " " << "(8) Australian Dollars";
    cout << "
    " << " " << "(9) U.S. Dollars

    ";
    }
    //This function prompts user for selection.
    int GetCurrencySelection(int& currencySelection)
    {
    cout << "Please enter your selection: ";
    cin >> currencySelection;
    cout << endl << endl;
    return 1;
    }

    //This function test the value to make sure it is within the range.
    bool IsCurrencySelectionValid(int currencySelection)
    {
    auto bool bRetVal;

    if (currencySelection < 1)
    {
    bRetVal = false;
    cout << "Error you must select a range between 1-9. Press any key to continue.";
    getch();
    exit(1);
    }
    else if(currencySelection > 9)
    {
    bRetVal = false;
    cout << "Error you must select a range between 1-9. Press any key to continue.";
    getch();
    exit(1);
    }
    else
    {
    bRetVal = true;
    }
    return (bRetVal);
    }

    //Function to calculate selection with current rate.
    double CalcExchangeAmount(double& dollars, int currencySelection)
    {
    switch (currencySelection)
    {
    case 1 : dollars = French_Franks * (dollar);
    break;
    case 2 : dollars = Italian_Lira * (dollar);
    break;
    case 3 : dollars = Japanese_Yen * (dollar);
    break;
    case 4 : dollars = German_Marks * (dollar);
    break;
    case 5 : dollars = Euros * (dollar);
    break;
    case 6 : dollars = British_Pounds * (dollar);
    break;
    case 7 : dollars = Canadian_Dollars * (dollar);
    break;
    case 8 : dollars = Australian_Dollars * (dollar);
    break;
    case 9 : dollars = US_Dollars * (dollar);
    break;
    }
    return 1;
    }

    //Function to display the calculations
    void DisplayResults(int currencySelection, double exchangeAmount,
    double dollarAmount)
    {

    CalcExchangeAmount(exchangeAmount, dollarAmount);
    (exchangeAmount) = (dollar);

    if(currencySelection == 1)
    {

    cout << "$" << fabs(exchangeAmount) << " is ";
    cout << fixed << setprecision(4) << dollarAmount << " French Franks";

    }
    else if(currencySelection == 2)
    {
    cout << "$" << fabs(exchangeAmount) << " is ";
    cout << fixed << setprecision(4)<< dollarAmount << " Italian Lira";
    }
    else if(currencySelection == 3)
    {
    cout << "$" << fabs(exchangeAmount) << " is ";
    cout << fixed << setprecision(4) << dollarAmount << " Japanese Yen";
    }
    else if(currencySelection == 4)
    {
    cout << "$" << fabs(exchangeAmount) << " is ";
    cout << fixed << setprecision(4) << dollarAmount << " German Marks";
    }
    else if(currencySelection == 5)
    {
    cout << "$" << fabs(exchangeAmount) << " is ";
    cout << fixed << setprecision(4) << dollarAmount << " Euros";
    }
    else if(currencySelection == 6)
    {
    cout << "$" << fabs(exchangeAmount) << " is ";
    cout << fixed << setprecision(4) << dollarAmount << " British Pounds";
    }
    else if(currencySelection == 7)
    {
    cout << "$" << fabs(exchangeAmount) << " is ";
    cout << fixed << setprecision(4) << dollarAmount << " Canadian Dollars";
    }
    else if(currencySelection == 8)
    {
    cout << "$" << fabs(exchangeAmount) << " is ";
    cout << fixed << setprecision(4) << dollarAmount << " Australian Dollars";
    }
    else
    {
    cout << "$" << fabs(exchangeAmount) << " is ";
    cout << fixed << setprecision(2) << dollarAmount << " U.S Dollars";
    }
    }




















  • brycebryce Member Posts: 25
    [b][red]This message was edited by bryce at 2002-10-25 8:6:12[/red][/b][hr]
    You would want to change the setprecision function
    for each currency correctness. See US for example.

    Some currencies around the world use 4 decimal places.

    Bryce

    : Im tring to program a money counting fuction in C++, but I can't figure out how to do it. I want it to count in integers using this range: 5 - 30,000. Any ideas? The program is for a game that Im creating, My game is pretty sweet!
    :



  • Shawn CarterShawn Carter Member Posts: 0

    ______ ( http://forcoder.org ) free video tutorials and ebooks about < Assembly, MATLAB, PL/SQL, PHP, Objective-C, Python, Perl, R, Scratch, Ruby, JavaScript, C, C#, Delphi, Visual Basic .NET, Go, C++, Java, Swift, Visual Basic Crystal, Kotlin, Julia, Lisp, Ada, Rust, Erlang, Bash, F#, Awk, VBScript, COBOL, ABAP, Hack, D, Apex, Scala, Fortran, Transact-SQL, Logo, SAS, Prolog, ML, LabVIEW, Dart, FoxPro, Alice, Scheme, Lua, Clojure /> ____________

Sign In or Register to comment.