944,150 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 8668
  • C++ RSS
Oct 23rd, 2004
0

help with getting soda machine program running

Expand Post »
I need help with the source code that I am going to attach. I have all of the pieces but I cannot figure out to put the pieces together.

I am to ( 1) have a display showing denominations of money accepted, total amount deposited, price of a soda, and a coin return that shows coins rejected (like pennies), and change returned by denomination (two dimes and one nickel, for example).

(2) the program should dispense a soda when an adequate deposit has been made.
(3) the program should repeat until told to quit.
(4) as with real soda machines, it should randomly take a customers money without dispensing a soda.
I can improve/improvise on the basics for extra credit.
This program is due no later than Oct 25, 2004.

Please I need help. This is the code that I have been trying to get to work for days now and I can't get it to work.

Please send me any help and source code so that I can finish this project. My lab teacher does not give us a lot of instruction on different programs, he only gives us a few examples and expects us to do the rest.

Thanks for any help and source code,
Jeannette

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <conio.h>
  4. #include <cstdlib>
  5. // #include <cmath>
  6.  
  7.  
  8. using std::setprecision;
  9. using std::setw;
  10.  
  11. using std::cin;
  12. using std::cout;
  13. using std::endl;
  14. using std::fixed;
  15. char flag = 'N';
  16.  
  17.  
  18.  
  19. void display();
  20. int coke();
  21. int reject();
  22. void takemoney ( void );
  23. int buy();
  24.  
  25. int deposit = 0;
  26. double coinreturn;
  27. int money;
  28.  
  29.  
  30. int main()
  31. {
  32.  
  33. int sum;
  34.  
  35. cout << "Enter coin: \t";
  36. cin >> deposit;
  37. deposit++;
  38. sum = coke();
  39.  
  40.  
  41. // display();
  42.  
  43. // takemoney();
  44. // buy();
  45.  
  46.  
  47. // cout <<"Do you want to continue to buy another drink?" << endl;
  48. // cin >> flag;
  49.  
  50. return 0;
  51.  
  52.  
  53. }
  54.  
  55.  
  56. // display function
  57. // displays the screen for buying a drink
  58.  
  59. void display()
  60. {
  61.  
  62. double slot = 0;
  63. double rejected = 0;
  64. double money = 0;
  65. double deposit = 0;
  66. // int sum;
  67.  
  68.  
  69. cout << "\t\t **********************" << endl;
  70. cout << "\t\t\tSODA MACHINE" << endl;
  71. cout << "\t\t **********************" << endl << endl;
  72. cout << "Soda $1.00" << endl << endl;
  73. cout << "Money accepted: Dollar, Quarters, Dimes, Nickels"
  74. << endl;
  75. cout << "\t\t($1.00)\t (.25)\t (.10)\t (.05)" << endl << endl;
  76.  
  77.  
  78. cout << "Enter coin: \t";
  79. cin >> deposit;
  80. coke();
  81.  
  82. // money += deposit;
  83. // slot += deposit;
  84. // rejected -= deposit;
  85.  
  86. // int coke();
  87.  
  88. cout << "Total Amount Deposited: \t\t" << fixed << setprecision ( 2 ) << money << endl;
  89.  
  90. cout << "Slot: \t" << fixed << setprecision ( 2 ) << slot << endl;
  91.  
  92. cout << "Coin return: \t" << endl;
  93.  
  94. //
  95. // reject();
  96.  
  97. }
  98.  
  99.  
  100. // function for entering money and status of money
  101.  
  102. int coke()
  103. {
  104. double deposit = 0;
  105. double money = 0;
  106.  
  107. if ( deposit == 1.00 )
  108. {
  109. ++money;
  110. cout << "You have deposited the correct amount!" << endl;
  111. cout << "Here is your soda!" << endl;
  112. }
  113.  
  114. if ( deposit == .05 )
  115. {
  116. ++money;
  117. cout << "Deposit more money!" << endl;
  118. }
  119.  
  120. if ( deposit == .10 )
  121. {
  122. ++money;
  123. cout << "Deposit more money!" << endl;
  124. }
  125.  
  126. if ( deposit == .25 )
  127. {
  128. ++money;
  129. cout << "Deposit more money!" << endl;
  130. }
  131.  
  132. // if ( deposit == .50 )
  133. // {
  134. // ++money;
  135. // cout << "Deposit more money!" << endl;
  136. // }
  137.  
  138. // if ( deposit == .75 )
  139. // {
  140. // ++money;
  141. // cout << "Deposit more money!" << endl;
  142. // }
  143.  
  144.  
  145.  
  146. return deposit;
  147.  
  148. }
  149.  
  150.  
  151. // function to reject money
  152. int reject()
  153. {
  154.  
  155. double rejected = 0;
  156. double slot;
  157.  
  158. if ( deposit > .01 || deposit < .05 )
  159. {
  160. money = 0;
  161. deposit = 0;
  162. slot = rejected;
  163. // rejected -= deposit;
  164. cout << "WRONG AMOUNT, ENTER CORRECT COINS!" << endl << endl;
  165. }
  166. return slot;
  167.  
  168. }
  169.  
  170.  
  171.  
  172. // function for taking money and giving no drink
  173.  
  174. void takemoney( void )
  175. {
  176. money = rand() % 5;
  177. if ( money == .50 )
  178. money = 0;
  179.  
  180. cout << "Lost money" << endl;
  181. cout << "No drink" << endl;
  182. }
  183.  
  184.  
  185. // function to continue buying a drink
  186.  
  187. int buy()
  188. {
  189. // int sum;
  190. char flag = 'N';
  191. int N = 0;
  192.  
  193.  
  194. if ( flag == 'Y' || flag == 'y' )
  195. // cout << "Enter deposit to continue: ";
  196. // cin >> flag;
  197. coke();
  198.  
  199. return flag;
  200.  
  201. }
Last edited by alc6379; Dec 8th, 2004 at 6:28 pm. Reason: added [code] tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jeannette1960 is offline Offline
3 posts
since Oct 2004
Oct 23rd, 2004
0

Re: help with getting soda machine program running

>help with getting soda machine program running
C++ Syntax (Toggle Plain Text)
  1. bool fix ( const soda_machine& machine)
  2. {
  3. kick ( machine );
  4. slap ( machine );
  5. shake ( machine );
  6. curse_at ( machine );
  7.  
  8. return machine->is_working;
  9. }
  10.  
  11. ...
  12.  
  13. if ( !machine.is_working && !fix ( machine ) )
  14. call_repairman ( machine.serial_number );
But seriously, if you divide your program into easy chunks, you won't encounter problems like this. I believe that your problem is trying to bite off more than you can chew, then choking on it.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 23rd, 2004
0

Re: help with getting soda machine program running

If I divide this program into smaller chunks, can I call different chunks through smaller chunks? I tried doing some of that but it didn't work. Can you please give me some more hints or suggestions on how I call a function within another function? The textbook that I am using does not show how to do this.

Thank you,
Jeannette
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jeannette1960 is offline Offline
3 posts
since Oct 2004
Oct 24th, 2004
0

Re: help with getting soda machine program running

You don't have to break everything up into functions at this point, just solve the different parts of the problem separately. Write a program to take the proper user input, write a program to make change, write a program to eat money randomly. Then, you know how to do each of the parts and can put them all together into one program. You can probably even transplant code from your other programs into the big program. Breaking up a problem into several solvable problems doesn't require modularization like you seem to think.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 24th, 2004
0

Re: help with getting soda machine program running

not trying to be a smart ass, but would that be also called the functional decomposition?
Reputation Points: 14
Solved Threads: 1
Light Poster
Coach_Nate is offline Offline
48 posts
since Aug 2004
Dec 8th, 2004
0

Re: help with getting soda machine program running

i haven done it but it will help what i have done
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <cstdlib>
// #include <cmath>


using std::setprecision;
using std::setw;

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
char flag = 'N';



void display();
int coke();
int reject();
void takemoney ( void );
int buy();

int deposit = 0;
double coinreturn;
int money;


void main()
{

display();
takemoney ( );

int sum;

cout << "Enter coin: \t";
cin >> deposit;
deposit++;
sum = coke();



}

void display()
{

double slot = 0;
double rejected = 0;
double money = 0;
double deposit = 0;
// int sum;


cout << "\t\t **********************" << endl;
cout << "\t\t\tSODA MACHINE" << endl;
cout << "\t\t **********************" << endl << endl;
cout << "Soda $1.00" << endl << endl;
cout << "Money accepted: Dollar, Quarters, Dimes, Nickels"
<< endl;
cout << "\t\t($1.00)\t (.25)\t (.10)\t (.05)" << endl << endl;


cout << "Enter coin: \t";
cin >> deposit;
coke();


cout << "Total Amount Deposited: \t\t" << fixed << setprecision ( 2 ) << money << endl;

cout << "Slot: \t" << fixed << setprecision ( 2 ) << slot << endl;

cout << "Coin return: \t" << endl;
}

int coke()
{
double deposit = 0;
double money = 0;

if ( deposit == 1.00 )
{
++money;
cout << "You have deposited the correct amount!" << endl;
cout << "Here is your soda!" << endl;
}

if ( deposit == .05 )
{
++money;
cout << "Deposit more money!" << endl;
}

if ( deposit == .10 )
{
++money;
cout << "Deposit more money!" << endl;
}

if ( deposit == .25 )
{
++money;
cout << "Deposit more money!" << endl;
}


return deposit;

}


int reject()
{

double rejected = 0;
double slot;

if ( deposit > .01 || deposit < .05 )
{
money = 0;
deposit = 0;
slot = rejected;

cout << "WRONG AMOUNT, ENTER CORRECT COINS!" << endl << endl;
}
return slot;

}


void takemoney( void )
{
money = rand() % 5;
if ( money == .50 )
money = 0;

cout << "Lost money" << endl;
cout << "No drink" << endl;
}



int buy()
{

char flag = 'N';
int N = 0;


if ( flag == 'Y' || flag == 'y' )

coke();

return flag;

}


email me on yb1pls@yahoo.co.uk if you still confused
Reputation Points: 11
Solved Threads: 1
Newbie Poster
yb1pls is offline Offline
24 posts
since Dec 2004
Dec 8th, 2004
0

Re: help with getting soda machine program running

yb1pls: Let sleeping threads lie!

And please learn to use [CODE][/CODE] tags!

And read the Announcement.

And do some searches to find out why void main() is wrong.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: the beginner needs help
Next Thread in C++ Forum Timeline: print a number in ordered form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC