aumming the digits

* Philippine currency is broken down into 1000,500,100,50,20,10 peso bills and 1 peso coin.
Write a program that would input an integer amount in peso and output the breakdown in bills and coins that would add up to that amount. For example, the amount 3,998 would be, 3 P100-bills,1 P500-bills, 4
P100-bills,1 P50-bill,1 P20-bill, 1 P10-bill,8 P1-coin.

* (Summing the digits in an integer) write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. for example, if an integer is 932, the sum of all its digits is 14.


i tried to do this and as usual it didnt work..
ahmM.. i'm looking for some1one who will do this, with explanation... f its ok,,
so i'll learn.. tnx..

How much do you pay?
I've done a few of your programs for you and I can tell you that by solving your problem here for you, you will not learn anything. Don't go over your head with maths in your programs, it will slow you down. First learn the concepts that C++ uses, then start building programs. Letting us solve your problem is generally not useful for you.
Last edited on
..hMm,, ok,, i'Ll just try again..
but pls,, check it for me,,
thank you
I'll give you a hint, integer division.
whew..10:13 pm, i feel sleepy already..
..i dont know how to extract remainder..
would you give me an example..?
tnx
I'm prepared to give you the efficient code for both of these problems, but don't expect them to be either easy to learn from or expect from me to create any program for you afterwards. Tell me whether you want it or you don't want it.
A small example on remainders:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
int main()
{
    std::cout << "5/3=" << 5/3 << std::endl; // Integer division
    std::cout << "5%3=" << 5%3 << std::endl; // Modulo, aka, remainder
    
    std::cout << "(5/3)*3=" << (5/3)*3 << std::endl;
// Due to the fact that integer division discards the decimal part of the expression,
// multiplying the outcome of an integer division by the dividend, would give you the
// amount of 3's (in this case) are in the starting integer. In this case 3 can be fully
// placed inside 5 exactly one time and thus the outcome is 1*3=3 (instead of 5).
    system("pause"); // Calls some BATCH codes to keep the window open
    return 0;
}
Last edited on
i'll just continue this tommorrow...
ZzZZz..
my head aches,,

no sleep since friday...
harhar.. stupid acquaintance party..

tnx for those who helped me,, specially Kyon..

=)
oh.. tnx.. for the sample..
tomorrow again... huh??
harhar..
..hard choices..
maybe i'll just answer that tomorrow....
i'll try it first,, is that ok??
harhar..
Heh, it's just that I am willing to invest time in helping people, but mainly that is not through giving the concrete answer to the question, rather guiding someone to the final answer. It's up to you to choose. Just a side-note, click the icon with the piece of paper and the pencil to edit your posts, some people are not really fond of double-posters. ;)
#include <iostream>
using namespace std;
int main ()
{

int amount;
int result; // initial value unidentified
int var1 = 1000; //initial value = 1000
int var2 = 500;  //initial value = 500
int var3 = 100;  //initial value = 100
int var4 = 50; //initial value = 50
int var5 = 20; //initial value = 20
int var6 = 10; //initial value = 10
int var7 = 1; //initial value = 1

cout << "Enter the amount:" << endl;
cin>> amount;
cout<<"\nThe amount "<< amount;
cout<<" would be:\n\n";
cout<<amount/var1 <<" P1000 bills.\n\n";
cout<<(amount%var1)/var2<<" P500 bills.\n\n";
cout<<(amount%var1)%var2/var3<<" P100 bills.\n\n";
cout<<(amount%var1)%var2%var3/var4<<" P50 bill.\n\n";
cout<<(amount%var1)%var2%var3%var4/var5<<" P20 bill.\n\n";
cout<<(amount%var1)%var2%var3%var4%var5/var6<<" P10 bill.\n\n";
cout<<(amount%var1)%var2%var3%var4%var5%var6/var7<<" P1 coins bill.\n\n";


return 0;
}



hey look.. i made it.. hahaha
it run.. im so happy..
one down.. one more to go...
:)

The second uses integer division as well, although the amounts to divide by might be a little less obvious. I will show you how I did the first one, in contradiction to yours. You might actually understand. :P (I'll still help you after, since this ain't spoiling any results, just showing a different approach). Here goes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
int main()
{
        unsigned int Money(0);
        unsigned int Thousand(0);
        unsigned int FiveHundred(0);
        unsigned int Hundred(0);
        unsigned int Fifty(0);
        unsigned int Twenty(0);
        unsigned int Ten(0);
        std::cout << "Insert the amount of cash to check: ";
        std::cin >> Money;
        std::cin.clear(); // When wrong input is given (digits mixed up with characters like 'y'), your program won't crash, when none-wrong input is given, the right value is in Money
        Money-=(Thousand = Money/1000)*1000;
        Money-=(FiveHundred = Money/500)*500;
        Money-=(Hundred = Money/100)*100;
        Money-=(Fifty = Money/50)*50;
        Money-=(Twenty = Money/20)*20;
        Money-=(Ten = Money/10)*10;
        std::cout << "1000 bills: " << Thousand << std::endl;
        std::cout << "500 bills: " << FiveHundred << std::endl;
        std::cout << "100 bills: " << Hundred << std::endl;
        std::cout << "50 bills: " << Fifty << std::endl;
        std::cout << "20 bills: " << Twenty << std::endl;
        std::cout << "10 bills: " << Ten << std::endl;
        std::cout << "Spare coins: " << Money << std::endl;
        system("pause"); // Use Batch to keep the console open
        return 0;
}

As shown, I use Money to keep track of the amount left (instead of doing nested modulo). This also means that I dont have to do the last equation, since Money is already in a good state at the end (since it is always a value between 10 and 0).
Last edited on
Topic archived. No new replies allowed.