Need help for code

May 14, 2012 at 4:50pm
Hey I was having some trouble on this code that requires me to write a program where a certain amount of money is input and what prints to the screen is the amount of money put in split into fifties, twenties, tens, fives, toonies, loonies, quarters, dimes, nickels and pennies. I am trying to write the program with the use of 'if' statements.
For example, 1567 (in cents) should print: 1567 cents requires 1 ten dollar bill, 1 five dollar bill, 2 quarters, 1 dime, 1 nickel, 2 pennies.
I can't seem to get the program to work correctly and would greatly appreciate some help. Thanks if you can help!
Last edited on May 14, 2012 at 4:51pm
May 14, 2012 at 4:53pm
Randy, mind reading costs extra! :) Can you post your code (using the code tags under format) so we can help you?
May 14, 2012 at 5:02pm
Sorry, give me a few minutes please.
May 14, 2012 at 5:07pm
I am so sorry i need to re write the program because it didnt save! I will get the code on here as soon as possible i promise!
May 14, 2012 at 5:32pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

void main() 
{
int Amount=1567; 
{
  if (Amount >= 5000)
	  if (Amount < 10000) 
   cout<< "1 fifty dollar bill, " <<endl;
}
{
  if (Amount >= 2000)
	  if (Amount < 5000) 
   cout<< "1 twenty dollar bill, " <<endl;
}
{
  if (Amount >= 1000)
	  if (Amount < 2000) 
   cout<< "1 ten dollar bill, " <<endl;
}
{
  if (Amount >= 500)
	  if (Amount < 1000) 
   cout<< "1 five dollar bill, " <<endl;
}
{
  if (Amount >= 200)
	  if (Amount < 500) 
   cout<< "1 toonie, " <<endl;
}
{
  if (Amount >= 100)
	  if (Amount < 200) 
   cout<< "1 loonie, " <<endl;
}
{
  if (Amount >= 25)
	  if (Amount < 100) 
   cout<< "1 quarter, " <<endl;
}
{
  if (Amount >= 10)
	  if (Amount < 25) 
   cout<< "1 dime, " <<endl;
}
{
  if (Amount >= 5)
	  if (Amount < 10) 
   cout<< "1 nickel, " <<endl;
}
{
  if (Amount >= 1)
	  if (Amount < 5) 
   cout<< "1 penny" <<endl;
}
								 
  system ("pause");
}//end main   

1 ten dollar bill,  


I can see the problem here, but do you know any way to fix it so it gives all of the info?
Last edited on May 14, 2012 at 5:34pm
May 14, 2012 at 5:46pm
if you are using borland compiler it does not support system("pause"); it supports getch(); and if you are using devcpp then it supports int main() not void.
And also check the braces { } before the if statements and remove them.
please give me a day or two i will examine the codes and give u reply.
May 14, 2012 at 5:49pm
Ok I have the time so sounds good, and thank you.
May 14, 2012 at 6:18pm
@randy825

You have to improve the logic a bit.
Like the section for $50. You have
1
2
3
4
5
{
  if (Amount >= 5000)
	  if (Amount < 10000) 
   cout<< "1 fifty dollar bill, " <<endl;
}
Try something more along this line.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int fifty=0,twenty=0,..;//and a variable for each currency amount
{
int Amount=12567, fifty=0,twenty=0; // Oops, didn't mean to duplicate the variables. Already initialized to zero, above 
  while (Amount >= 5000)
  {
	  fifty++;
	  Amount-=5000;
  };
   if(fifty>0)  // Only prints next line IF you have 1 or more fifty dollar bills
	   cout << "You get " << fifty << " Fifty dollar bills." << endl;
while (Amount >= 2000)
  {
	  twenty++;
	  Amount-=2000;
  };
	if (twenty>0)  // Only prints next line IF you have 1 or more twenty dollar bills
		cout << "You get " << twenty << " Twenty dollar bills." << endl;

// ----etc. with the rest 
Last edited on May 15, 2012 at 5:29pm
May 15, 2012 at 4:58pm
Thank you very much! I will try to understand everything that is going on in this code to the best of my abilities as a beginner.
May 16, 2012 at 4:45pm
I use Microsoft Visual C++ 2010 Express
May 16, 2012 at 5:00pm
Very good program. I use Microsoft Visual C++ 2008 Express. So far, don't feel like upgrading to newer version. So, how's this program coming along now?
May 18, 2012 at 4:49pm
Its pretty good the program works and more importantly, I know how it works! I mean the code but a lot of the tools and functions in Microsoft Visual C++ 2010 Express I don't even get. I basically only use the build and the run button.
Topic archived. No new replies allowed.