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:
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.
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])
}
}
#include<iostream>
usingnamespace 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])
}
}