pls help..

paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1..

create a program that will count all the paper bills in
the number being input..

example:
enter a number: 3886

there is/are:

3 ->1000
1 ->500
3 ->100
1 ->50
1 ->20
1 ->10
1 ->5
1 ->1

example2:
enter a number: 728

there is/are:

0 ->1000
1 ->500
2 ->100
0 ->50
1 ->20
0 ->10
1 ->5
3 ->1

Answers were Sorted based on User's Feedback



pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count ..

Answer / etay

int _tmain(int argc, _TCHAR* argv[])
{
int num,i;
int bills[8] = { 1000, 500, 100, 50 ,20 ,10 ,5 ,1 };
int count[8] = {0};
printf("insert the number: \n");
scanf("%d",&num);
for (i=0; i<8;i++)
{
while (num >= bills[i])
{
num-=bills[i];
count[i]++;
}
}

for (i=0;i<8;i++)
{
printf("%d = %d \n",bills[i],count[i]);
}
scanf("%d",&num);

return 0;
}

Is This Answer Correct ?    6 Yes 1 No

pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count ..

Answer / aruna

The above program works gud. But I have small suggestion.

bill_count[i] = (val>=5?val/bill[i]:val);

This val >=5 will be executed every time though it is not
needed. Simpley we can give Quotient value in bill_count[i].
ie
bill_count[i] = val/bill[i];

Is This Answer Correct ?    3 Yes 0 No

pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count ..

Answer / subrata

#include<iostream>
using namespace std;



int main()
{
int bill[]={1000, 500, 100, 50, 20, 10, 5, 1};
int bill_count[]={0,0,0,0,0,0,0,0};

int size=8;
int val=728;


for(int i=0; i<size; i++)
{
if(val > bill[i] )
{

bill_count[i] = (val>=5?val/bill[i]:val);
val = val%bill[i];

}
}

for(int i=0; i<size; i++)
{
cout<< bill_count[i]<<" X " << bill[i]<<endl;
}

system("pause");
exit(0);
}

Is This Answer Correct ?    5 Yes 5 No

pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count ..

Answer / anand

nt main()
{
int number,count;
int currency[] = {1000, 500,100,50, 20, 10,5, 1};
cout<<"enter the number";
cin>>number;
for(int i=0; i<8;++i)
{
count = 0;
while(number >= currency[i])
{
number -= currency[i];
++count;
}
cout<<count<<"---"<<currency[i]<<"notes"<<endl;
}

getchar();
cout<<endl;

return 0;
}

Is This Answer Correct ?    4 Yes 4 No

Post New Answer

More C++ General Interview Questions

Explain object slicing in c++?

0 Answers  


Write a Program for dynamically intialize a 2 dimentional array. Eg:5x20, accept strings and check for vowels and display the no.finally free the space allocated .

0 Answers  


How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Why is it difficult to store linked list in an array?how can you find the nodes with repetetive data in a linked list?

0 Answers  


Tell me an example where stacks are useful?

0 Answers  


What are activex and ole?

0 Answers  






What do you mean by function and operator overloading in c++?

0 Answers  


Which uses less memory? a) struct astruct { int x; float y; int v; }; b) union aunion { int x; float v; }; c) char array[10];

4 Answers   Quark,


What is oop in c++?

0 Answers  


What is a linked list in c++?

0 Answers  


Any one help me plzzzz..... i have an assignment...... that is ______*********_______ Write a program that takes an equation as a string and does the following: Solve 8 parts to achieve 100% 1 - 5 are compulsory. Input: 2x^2+3x+4=0 1) read a quadratic equation 2) print its coefficients (coefficients range is 0 to 9) 3) print the solution of the equation 4) tackle imaginary solution e.g. ( (2+3i), (2-3i) ) 5) allow spaces within the input 6) after solving one equation; ask for an other, terminate on empty line. * 7) tackle negative values as well * 8) tackle more than one values of same exponent (e.g. 2x^2 + 3x^2 + 4x + 3 = 0)* 9) use strtok * 10) print the solution in fractions e.g. 1.5 should be printed as (1)1/2 * 11) coefficient can be greater than 9** 12) values on both sides of the ‘=’ sign** 13) plot the graph of the polynomial** 14) use a compiler other than Borland** 15) submit before May 25, 2009 11:59 PM ** _______******________ plz send me c++ code at sweety.alvi@gmail.com

1 Answers  


What is the latest c++ standard?

0 Answers  


what is data abstraction in C++?

0 Answers  


Categories