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
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 |
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 |
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 |
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 |
Define anonymous class.
What are function poinetrs? where are they used?
Why is main function important?
When is the destructor called?
what is multi-threading in C++?
What is the best c++ compiler?
Implement stack operations with pointers with appropriate exception checks.
How do you clear a buffer in c++?
what is the use of templates?
How to declaring variables in c++?
How is new() different from malloc()?
What are friend classes? What are advantages of using friend classes?