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

#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;


int main()
{

	int sum;

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

	
//	display();
	
//	takemoney();
//	buy();
	

//	cout <<"Do you want to continue to buy another drink?" << endl;
//	cin >> flag;
	
	return 0;


}


// display function
// displays the screen for buying a drink

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();
		
//		money += deposit;
//		slot += deposit;
//		rejected -= deposit;

//		int 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;

//	
//	reject();
	
}


// function for entering money and status of money

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;
		}

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

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

	

	return deposit;

}


// function to reject money
int reject()
{

	double rejected = 0;
	double slot;

	if ( deposit > .01 || deposit < .05 )
		{
			money = 0;
			deposit = 0;
			slot = rejected;
//			rejected -= deposit;
			cout << "WRONG AMOUNT, ENTER CORRECT COINS!" << endl << endl;
		}
	return slot;

}



// function for taking money and giving no drink

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

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


// function to continue buying a drink

int buy()
{
//	int sum;
	char flag = 'N';
	int N = 0;


		if ( flag == 'Y' || flag == 'y' )
//			cout << "Enter deposit to continue: ";
//			cin >> flag;
			coke();

		return flag;
			
}

>help with getting soda machine program running

bool fix ( const soda_machine& machine)
{
  kick ( machine );
  slap ( machine );
  shake ( machine );
  curse_at ( machine );

  return machine->is_working;
}

...

if ( !machine.is_working && !fix ( machine ) )
  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.

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

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.

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

This article has been dead for over six months. Start a new discussion instead.