Thread: prog in C

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    6

    Question prog in C

    at the end I am supposed to output how many coins which ones and the amount of each and then the total amt....can't seem to get past jonnies ($1.21)....HELP?!?!?!?!? quickly....

    #include <iostream.h>
    #include <stdlib.h>
    int main()
    {
    int maxcoin, coinnum, twoonnum, loonnum, currenttwoonie;
    int quarternum, dimenum, nickelnum, pennynum, twonnies;
    float currentamt,totalcoin, currentamt1, maxjonnie, jonnienum;
    maxcoin = 10000;
    cout<<("Enter amount:");
    cin>>currentamt;
    currentamt1 = currentamt * 100; //1.26 * 100 = 126
    maxjonnie = currentamt1/121; //443 / 121 = 3.66115
    for (jonnienum = 0; jonnienum <= maxjonnie; jonnienum ++);
    {
    pennynum = 0;
    nickelnum = 0;
    dimenum = 0;
    quarternum = 0;
    loonnum = 0;
    jonnienum = 0;
    twoonnum = 0;

    currentamt = currentamt - (121 * jonnienum); //6.05 - (121 *

    while (currentamt >= 200);
    {
    currentamt = currentamt - 200;
    twoonnum = twoonnum + 1;
    }
    while (currentamt >= 100);
    {
    currentamt = currentamt - 100;
    loonnum = loonnum + 1;
    }
    while (currentamt >= 25);
    {
    currentamt = currentamt - 25;
    quarternum = quarternum + 1;
    }
    while (currentamt >=10);
    {
    currentamt = currentamt - 10;
    dimenum = dimenum + 1;
    }
    while (currentamt >=5);
    {
    currentamt = currentamt - 5;
    nickelnum = nickelnum + 1;
    }
    while (currentamt >=1);
    {
    currentamt = currentamt - 1;
    pennynum = pennynum + 1;
    }
    coinnum = jonnienum+twoonnum+loonnum+quarternum+dimenum+nick elnum+pennynum;
    if (coinnum < maxcoin);
    {
    maxcoin = coinnum;
    jonnienum = maxjonnie;
    }
    //we know how many coins in the and how many jonnies
    cout<<maxjonnie<<" "<<("Jonnies:")<<" "<<maxjonnie*1.21<<endl;
    cout<<twoonnum<<" "<<("Twonnies:")<<" "<<twoonnum*2<<endl;
    //works up to this point
    cout<<("The least amount of coins required to make up")<<endl;
    cout<<" "<<"$"<<currentamt1/100<<" "<<("is")<<" "<<coinnum<<endl;

    system("PAUSE");
    return 0;
    }
    }
    Last edited by daisy; 03-08-2003 at 12:09 PM.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You think we are mind readers?

    If not, attach the source code.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    YoDaddy
    Guest

    Unhappy

    can't you do something like this?:

    input a
    a/20 => number of 20s...round down..if it's under 20..it'll be zero
    a%20 => take mod=b
    b/10 => number of 10s round down
    b%10 => blah blah

    that's probably not the fastest way though...

  4. #4
    Black Mage Extraordinaire VegasSte's Avatar
    Join Date
    Oct 2002
    Posts
    167
    I would use two arrays, one to hold the name of the coin and one to hold(in the corresponding place) the number of that coin there are in the total. i would then use the mod symbol to work out how many coins there are!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assembly amature question: prog errors
    By geek@02 in forum Tech Board
    Replies: 1
    Last Post: 10-03-2008, 01:35 PM
  2. Getting input from another prog?
    By Badman3k in forum C Programming
    Replies: 4
    Last Post: 11-11-2004, 02:58 AM
  3. an option at the end of this prog to ask if I want to run again
    By bandito9111 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2003, 02:30 PM
  4. Try my prog...
    By Commander in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 05-09-2002, 07:43 AM
  5. password prog
    By ihsir in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-06-2002, 06:39 AM