just take a look at this problem.

I need someone who could help me in this problem. I can't give the detail explanation about the problem but this is the output.

Enter number: 1,245
1000=1
500=0
400=0
300=0
200=1
100=0

can you pls give me a hint how to do this problem.I don't get the logic of this.. thanks a lot.
Last edited on
It looks like you have to find a way to add up to the given number without going over.
yeah. do you have any idea about the process in solving this?
I have :)
but what code do you have so far?
receive a value
in order to to get the amount of each number present; ie. one 1000 in 1245, you have to divide the input by 1000. then you have to find the remainder so that you can find the amount of each subsequent value. and repeat the process until you have gone through each of the output numbers:

input
divide
find remainder
print
not divide but subtract.
subtracting could help with finding the remainder, but you would have to divide in order to determine how much of a given number is present in the input.
Here is the function I wrote

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int somefunction(int number)
{
    while(counter < 6)
    {
        {
        if (number - anarray[counter] >= 0)
            {
                cout << anarray[counter] << "=1" << endl;
                number -= anarray[counter];
            }
        else
            cout << anarray[counter] << "=0" << endl;
        }
        counter++;
    }
}
That would only be helpful for this specific instance. Without knowing the other details of the problem, you should want to make it as universal as possible.

1
2
3
4
5
6
7
8
9
int somefunction(int number)
{
   for (i = 0; i < array_length; i++)
     {
        result = number / array[i];
        cout << array[i] << " = " << result << endl;
        number = number % array[i]; // or number - (result * array[i])
     }
}
Last edited on
OK very nice :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
using namespace std;

int array[]= {1000,500,400,300,200,100};
int i=0;
int result=0;
int array_length = 6;
int number = 0;
int somefunction(int);
int main()
{
    cout << "enter number:";
    cin >> number;
    somefunction(number);
}
int somefunction(int number)
{
   for (i = 0; i < array_length; i++)
     {
        result = number / array[i];
        cout << array[i] << " = " << result << endl;
        number = number % array[i]; // or number - (result * array[i])
     }
}
yup yup :). Does this stuff help you out catherine?
lol she did her homework ;) you know how they say "Where two fight the third wins" lol ;)
Lol, very true. Hopefully she understands the logic behind it at least.
Yeah, cheating won't bring you any further :(
I haven't try it but I believe in you guys and don't worry I will analyze your codes. Thanks a lot for your help. :-)
Topic archived. No new replies allowed.