Hi, below is my c++ program this program is suppose to give the denomination of a given amount.
for example if the amount entered is 3897.69
the output should be like this:
1000 * 3 = 3000
500 * 1 = 500
200 * 1 = 200
100 * 1 = 100
50 * 1 = 50
and so on..
my problem evolves on the looping thing and the output. can you help me?
#include %26lt;iostream.h%26gt;
main()
{
int cntr;
int ans[14];
int value;
float d[14]={1000,500,200,100,50,20,10,5,1,0.5...
cout%26lt;%26lt;endl%26lt;%26lt;" Enter value: ";
cin %26gt;%26gt; value;
{
ans[cntr]=value/d[cntr];
value=value-d[cntr]*ans[cntr];
while(cntr%26gt;15)
{
cntr=cntr+1;
ans[cntr]=value/d[cntr];
}
cout%26lt;%26lt;" "%26lt;%26lt;d[cntr]%26lt;%26lt;" * "%26lt;%26lt;ans[cntr]%26lt;%26lt;" = "%26lt;%26lt;d[cntr]*ans[cntr]%26lt;%26lt;endl;
}
}
thanks in advance!
C++ help about looping.my program also involves arrays?
You're on the right track. The easiest way to do things such as this is by using the mod operator (%). The mod operator essentially returns the remainder of division by the second operand. For instance, take your value of 3897.69. Start at the biggest denomination of 1000.
total = 3897.69
remainder = total % 1000 = 897.69
then the number of thousands is floor(3897.69 / 1000)
total = remainder
You then just need to loop over that with each denomination and save the number of each denomination in a separate array. Do you understand how to generalize this now?
Reply:i don't know the script but i can help u with my logic
1. u must know how long number entered
2. count it and loop it
3. for first number multiply it with 1 join string zero (long number entered) - 1 and then convert it to decimal
example if 1 entered 1000 - %26gt; length = 4
so 1 * 1 000 ( 4 -1)
4. and take the number in the second row multiply with 1 join string zero (long number entered) - 2 and then convert it to decimal
5. and so on
Reply:just use
value=value%d[cntr];
instead of "value=value-d[cntr]*ans[cntr];"
can U wait a while I'hv to see prgramm carefully and then solve UR problem
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment