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

What are the differences between new and malloc?

0 Answers  


How a new element can be added or pushed in a stack?

0 Answers  


Describe the setting up of my member functions to avoid overriding by the derived class?

0 Answers  


What is the use of turbo c++?

0 Answers  


What are the differences between java and c++?

0 Answers  






What and all can a compiler provides by default?

3 Answers   Accenture, HP,


What is the most common mistake on c++ and oo projects?

0 Answers  


Can I learn c++ in a week?

0 Answers  


What is the use of typedef?

0 Answers  


Given the following seqment of code containing a group of nested if instructions: y = 9; if ((x==3) || (x == 5)) y++; else if (x == 2) y *= 2; else if (x == ) y-= 7; else y = 8; if the value of x is 4 before the nested IFs are executed, what is the value of y after the nested IFs are executed?

0 Answers  


Define Virtual function in C++.

0 Answers   iNautix,


How new/delete differs from malloc()/free?

0 Answers  


Categories