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 |
Write a corrected statement in c++ so that the statement will work properly. if (4 < x < 11) y=2*x;
Can we specify variable field width in a scanf() format string? If possible how?
What is flush c++?
Write about an iterator class?
Which software is used for c++ programming?
What is an adaptor class or wrapper class in c++?
What is a "Copy Constructor"?
What is stl containers in c++?
Explain terminate() and unexpected() function?
How do you compile the source code with your compiler?
Which is the best c++ compiler for beginners?
What is a constructor in c++ with example?