Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 28th, 2010, 11:15 PM   #11
joyo
Newbie
 
Join Date: Feb 2010
Posts: 19
Rep Power: 0 joyo is on a distinguished road
Re: Newbie Needs help with First Program

I am interest in the result of this question , it is interesting.
__________________
sky programmer
joyo is offline   Reply With Quote
Old Mar 1st, 2010, 9:11 AM   #12
Raikiriu
Hobbyist & CS Student
 
Raikiriu's Avatar
 
Join Date: Feb 2009
Location: Canada(Quebec)
Posts: 127
Rep Power: 2 Raikiriu is on a distinguished road
Send a message via MSN to Raikiriu
Re: Newbie Needs help with First Program

c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main (){
  6.  
  7. double price = 0.0;
  8. double amountTendered = 0.0;
  9. double change = 0.0;
  10.  
  11. int _50dollars;
  12. int _20dollars;
  13. int _10dollars;
  14. int _5dolars;
  15. int _1dollar;
  16. int _50centpieces;
  17. int quarters;
  18. int dimes;
  19. int nickels;
  20. int pennies;
  21.  
  22. cout << "enter price and press enter\n";
  23.  
  24. cin >> price;
  25.  
  26. cout << "enter amount tendered and press enter\n";
  27.  
  28. cin >> amountTendered;
  29.  
  30. change = price - amountTendered;
  31.  
  32. cout << "here's your change..Thank you:" << change << endl;
  33.  
  34. change = change * 100;
  35.  
  36. _50dollars = change/5000;
  37. change = change % 5000;
  38.  
  39. _20dollars = change/2000;
  40. change = change % 2000;
  41.  
  42. _10dollars = change/1000;
  43. change = change % 1000;
  44.  
  45. _5dollars = change/500;
  46. change = change % 500;
  47.  
  48. _1dollar = change/100;
  49. change = change % 100;
  50.  
  51. _50cent pieces = change/50;
  52. change = change % 50;
  53.  
  54. quarters = change/25;
  55. change = change % 25;
  56.  
  57. dimes = change/10;
  58. change = change % 10;
  59.  
  60. nickels = change/5;
  61. change = change % 5;
  62.  
  63. pennies = change/1;
  64. change = change % 1;
  65.  
  66. //This is one long ass cout statement.
  67. cout << "$50 bills:" << _50dollars << endl << "$20 bills:" << _20dollars << endl << _10dollars << "\n" << "$5 bills:" << _5dollars << endl << "$1 bills:" << _1dollar << endl << "$0.50 peices:" << _50centpices << endl << "$0.25 peices:" << quarters << "\n" << "$0.10 peices:" << dimes << endl << "$0.05 peices:" << nickels << endl << "$0.01 peices:" << pennies << endl;
  68.  
  69. return 0
  70. }
most of the syntax errors are fixed. I don't have my compiler installed so I can't check to see if it work. Good Luck.
__________________
Looking for a good Linear Programming e-book or Assembler e-book.
Raikiriu is offline   Reply With Quote
Old Mar 1st, 2010, 12:34 PM   #13
abdul.gafur
Trying to be a Real Coder
 
abdul.gafur's Avatar
 
Join Date: Feb 2010
Location: Salo, Riau, Indonesia
Posts: 112
Rep Power: 1 abdul.gafur is on a distinguished road
Send a message via Yahoo to abdul.gafur
Re: Newbie Needs help with First Program

I've tried the following code. Program runs as expected.

cpp Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. int main (){
  7.  
  8. double price = 0.0;
  9. double amountTendered = 0.0;
  10. double change = 0.0;
  11.  
  12. int intChange;
  13. int _50dollars;
  14. int _20dollars;
  15. int _10dollars;
  16. int _5dollars;
  17. int _1dollar;
  18. int _50centpieces;
  19. int quarters;
  20. int dimes;
  21. int nickels;
  22. int pennies;
  23.  
  24. cout << "enter price and press enter\n";
  25.  
  26. cin >> price;
  27.  
  28. cout << "enter amount tendered and press enter\n";
  29.  
  30. cin >> amountTendered;
  31.  
  32. change = price - amountTendered;
  33.  
  34. cout << "here's your change..Thank you:" << change << endl;
  35.  
  36. intChange = (int)(change * 100);
  37.  
  38. _50dollars = intChange/5000;
  39. intChange = intChange % 5000;
  40.  
  41. _20dollars = intChange/2000;
  42. intChange = intChange % 2000;
  43.  
  44. _10dollars = intChange/1000;
  45. intChange = intChange % 1000;
  46.  
  47. _5dollars = intChange/500;
  48. intChange = intChange % 500;
  49.  
  50. _1dollar = intChange/100;
  51. intChange = intChange % 100;
  52.  
  53. _50centpieces = intChange/50;
  54. intChange = intChange % 50;
  55.  
  56. quarters = intChange/25;
  57. intChange = intChange % 25;
  58.  
  59. dimes = intChange/10;
  60. intChange = intChange % 10;
  61.  
  62. nickels = intChange/5;
  63. intChange = intChange % 5;
  64.  
  65. pennies = intChange/1;
  66. intChange = intChange % 1;
  67.  
  68. //This is one long ass cout statement.
  69. cout << "$50 bills:" << _50dollars << endl << "$20 bills:" << _20dollars << endl << "$10 bills:" << _10dollars << endl << "$5 bills:" << _5dollars << endl << "$1 bills:" << _1dollar << endl << "$0.50 peices:" << _50centpieces << endl << "$0.25 peices:" << quarters << endl << "$0.10 peices:" << dimes << endl << "$0.05 peices:" << nickels << endl << "$0.01 peices:" << pennies << endl;
  70.  
  71. getch();
  72. return 0;
  73. }

Hope that helps.

Result :
Attached Images
File Type: png Untitled.png (30.8 KB, 6 views)
__________________
just a drop of dew in the morning
abdul.gafur is offline   Reply With Quote
Old Mar 1st, 2010, 2:04 PM   #14
ericsurf
Newbie
 
Join Date: Feb 2010
Posts: 6
Rep Power: 0 ericsurf is on a distinguished road
Re: Newbie Needs help with First Program

Here's what I have based on what we've learned so far. Doesn't compile and says "expected primary expression before 'int' on line 11. Any ideas? BTW...how do list code with the option to toggle plain text?

...and thanks a bunch!!!

#include <iostream>

using namespace std;

int main()
{
double price=0.0;
double amountTendered=0.0;
double change=0.0;

int 50_dollar_bills;
int 20_dollar bills;
int 10_dollar bills;
int 5_dollar bills;
int 1_dollar bills;
int 50CentPieces;
int quaters;
int dimes;
int nickels;
int pennies;

cout<<"Enter the Price and press Enter\n";
cin>>price;
cout<<"Enter the amount tendered\n";
cin>>amountTendered;
change = price-amountTendered;
cout>>"Here's your change....Thank You\n";

change=change*100;

50_dollar_bills=change/5000;
change=change%5000;

20_dollar_bills=change/2000;
change=change%2000;

10_dollar_bills=change/1000;
change=change%1000;

5_dollar_bills=change/500;
change=change%500;

1_dollar_bills=change/100;
change=change%100;

50CentPieces=change/50;
change=change%50;

quaters=change/25;
change=change%25;

dimes=change/10;
change=change%10;

nickels=change/5;
change=change%5;

pennies=change/1;
change=change%1;

cout>>"50_dollar_bills: ">>_50_dollar_bill>>endl"20_dollar_bills: ">>_20_dollar_bills>>endl>>
"10_dollar_bills: ">>_10_dollar_bills.>>endl>>"5_dollar_bills: ">>_5_dollar_bills>>endl>>
"1_dollar_bills: ">>_1_dollar_bills>>endl>>"50CentPieces: ">>_50CentPieces>>endl"Quaters: ">>quaters>>endl>>
"Dimes: ">>dimes>>endl"Nickels: ">>nickels>>endl>>"Pennies: ">>pennies>>endl;

return0;

}

Last edited by ericsurf; Mar 1st, 2010 at 2:06 PM. Reason: forgot to add some things
ericsurf is offline   Reply With Quote
Old Mar 1st, 2010, 8:51 PM   #15
abdul.gafur
Trying to be a Real Coder
 
abdul.gafur's Avatar
 
Join Date: Feb 2010
Location: Salo, Riau, Indonesia
Posts: 112
Rep Power: 1 abdul.gafur is on a distinguished road
Send a message via Yahoo to abdul.gafur
Re: Newbie Needs help with First Program

I dunno where line 11.

I think, Error occured in following code.
Quote:
cpp Syntax (Toggle Plain Text)
  1. int 20_dollar bills;
  2. int 10_dollar bills;
  3. int 5_dollar bills;
  4. int 1_dollar bills;
Replace with this one
cpp Syntax (Toggle Plain Text)
  1. int 20_dollar_bills;
  2. int 10_dollar_bills;
  3. int 5_dollar_bills;
  4. int 1_dollar_bills;

You may be able to try my program (My previous post).

Quote:
BTW...how do list code with the option to toggle plain text?
You hit # symbol at message bar, [CODE ] [/CODE ] will arise, you can insert your code between [CODE ] and [/CODE ] {without space}.
For C++ language, you add ='cpp' or ='c++' after CODE, [code='cpp' ] [/CODE ]
__________________
just a drop of dew in the morning
abdul.gafur is offline   Reply With Quote
Old Mar 2nd, 2010, 12:58 AM   #16
ericsurf
Newbie
 
Join Date: Feb 2010
Posts: 6
Rep Power: 0 ericsurf is on a distinguished road
Re: Newbie Needs help with First Program

Thanks so much for all the help folks! It turns out I had 3 small errors

1. White spaces when I declared some of my int variables.
2. I didn't change the variable "change" from a double to an integer after multiplying by 100 (convert to pennies)
3. Had several "<< " pointing in the wrong direction in the cout at the end.

Here's what gave me credit for the project:

cpp Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. double price,amountTendered,change;
  8.  
  9. int Fifty_dollar_bills,Twenty_dollar_bills,Ten_dollar_bills,
  10. Five_dollar_bills,One_dollar_bills,FiftyCentPieces,quaters,
  11. dimes,nickels,pennies,int_change;
  12.  
  13.  
  14. cout<<"Enter the Price and press Enter\n";
  15. cin>>price;
  16. cout<<"Enter the amount tendered\n";
  17. cin>>amountTendered;
  18. change = amountTendered-price;
  19. cout<<"Here's your change....Thank You\n";
  20.  
  21. int_change=int(change*100);
  22.  
  23. Fifty_dollar_bills=int_change/5000;
  24. int_change=int_change%5000;
  25.  
  26. Twenty_dollar_bills=int_change/2000;
  27. int_change=int_change%2000;
  28.  
  29. Ten_dollar_bills=int_change/1000;
  30. int_change=int_change%1000;
  31.  
  32. Five_dollar_bills=int_change/500;
  33. int_change=int_change%500;
  34.  
  35. One_dollar_bills=int_change/100;
  36. int_change=int_change%100;
  37.  
  38. FiftyCentPieces=int_change/50;
  39. int_change=int_change%50;
  40.  
  41. quaters=int_change/25;
  42. int_change=int_change%25;
  43.  
  44. dimes=int_change/10;
  45. int_change=int_change%10;
  46.  
  47. nickels=int_change/5;
  48. int_change=int_change%5;
  49.  
  50. pennies=int_change/1;
  51. int_change=int_change%1;
  52.  
  53. cout<<"50_dollar_bills: "<<Fifty_dollar_bills<<endl<<"20_dollar_bills: "
  54. <<Twenty_dollar_bills<<endl<<"10_dollar_bills: "<<Ten_dollar_bills
  55. <<endl<<"5_dollar_bills: "<<Five_dollar_bills<<endl<< "1_dollar_bills: "
  56. <<One_dollar_bills<<endl<<"50CentPieces: "<<FiftyCentPieces<<endl<<"Quaters: "
  57. <<quaters<<endl<<"Dimes: "<<dimes<<endl<<"Nickels: "<<nickels<<endl<<"Pennies: "
  58. <<pennies<<endl;
  59.  
  60. return 0;
  61.  
  62. }
ericsurf is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Language display in program Prm753 C++ 3 May 30th, 2006 5:45 PM
Creating a program to test a program sixstringartist C 8 Jan 21st, 2006 1:15 PM
Newbie: Masm32 program that beeps 6 times Johnny5 Assembly 2 Jun 12th, 2005 10:49 AM
Newbie needs help badly with his C++ program jamal227 C++ 2 Feb 19th, 2005 10:52 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC