• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Vending Machine Program - Not giving correct change. Need help desperatly!

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, I really need some help!! My brain has completly gone dead.
This is a long code, sorry for that, but if you could look at it and tell me why my change is only coming up zeros, I'd greatly appreciate it!

_________________________________________________________________________

#include <iostream.h>
#include <iomanip.h> //for the setw()


const int CANDYBAR = 65; //correct
const int CHIPS = 55; //correct
const int SODA = 90; //correct
const int HONEYBUN = 110; //correct

//prototypes

void Write_Menu(); //correct
void Get_Selection(int&, int&);//
int Get_Money();//correct
void Write_Money(int);//correct
void Write_Selection(int);//correct
int Get_Change(); //almost correct
void Write_Change(int& quarters, int& dimes, int& nickels, int&money, int& remainder);//almost correct
void Write_Change(int change); //almost correct...at least its writing the cout statement
int Get_MixtureOfChange();
void Write_Mixture(int);



//end prototypes



int main()

{

int selection;
int money;
int change;
//int quarters;
//int dimes;
//int nickels;
//int remainder;



Write_Menu(); //call--no return or inputs /correct
Get_Selection(selection, change);
Write_Selection(selection);//working on this one now..
money = Get_Money(); //correct
Write_Money(money);//correct
change = Get_Change();//new

Write_Change(change);//new

return 0;

} //end main

//functions beginning

void Write_Menu()

{

cout <<" "<<endl<<endl;
cout <<" ***************************************** "<<endl;
cout <<" * * "<<endl;
cout <<" * VENDING MACHINE * "<<endl;
cout <<" * * "<<endl;
cout <<" * Candy Bar - .65 - Press 1 * "<<endl;
cout <<" * Chips - .55 - Press 2 * "<<endl;
cout <<" * Soda - .90 - Press 3 * "<<endl;
cout <<" * Honey Bun - 1.10 - Press 4 * "<<endl;
cout <<" * * "<<endl;
cout <<" ***************************************** "<<endl;

}


void Get_Selection(int& selection, int& change)

{
//int selection = 0;
//int change = 0;
int money = 0;

cout <<" Please enter your selection."<<endl; //correct
cout <<" Then press Enter. "<<endl; //correct
cin >>selection; //correct
//return selection;//new -- not sure if this should be here..


switch(selection)

{

case 1:

cout <<" You chose a Candy Bar - .65"<<endl<<endl;
change = money - CANDYBAR;
break;

case 2:
cout <<" You chose Chips - .55"<<endl;
change = money-CHIPS;
break;

case 3:
cout <<" You chose a Soda - .90"<<endl;
change = money - SODA;
break;

case 4:
cout <<" You chose a Honey Bun - 1.10"<<endl;
change = money - HONEYBUN;
break;

//Default message if user makes a choice other than 1 - 4.

default:
cout<<" You must enter a selection between 1 and 4. Thank You!"<<endl<<endl;
}
//return selection;

}

void Write_Selection(int selection)
{
cout<<" You chose" << selection <<">"<<endl;
//return selection;// not sure if this should be here either.
}

int Get_Money()//correct
{
int money; //correct
cout <<" Please enter the dollar amount"<<endl;
cout <<" you are spending. Then press Enter."<<endl;
cin >>money;//correct
return money;//correct
}

void Write_Money(int money) //Input is an integer, no return value //**
{

cout <<" You gave me " << money << "."<<endl;

}


int Get_Change()

{

int change = 0;
int money = 0;
int selection = 0;
change = money - selection;


return change;
}

void Write_Change(int change)

{
int amount = 0;
int remainder;
int nickels = 0;
//int change;
int money = 0;
int choice = 0;
int dimes;
int quarters;

quarters = money/25;
remainder = amount%25;
dimes = money/10;
remainder = money%10;
remainder = remainder % 5;
//return change;
//int money;


cout <<" Your change is " <<change << "."<<endl;
cout <<" Quarters - " <<quarters/25 <<endl;
cout <<" Dimes - " <<change/10<<endl;
cout <<" Nickels - " <<nickels/5<<endl<<endl;
cout <<" Enjoy your snack!"<<endl;
cout <<" Thank you for shopping with us!"<<endl<<endl;
}

int Get_MixtureOfChange()
{
int amount = 0;
int remainder;
//int nickels;
int change = 0;
int money = 0;
int choice = 0;
int dimes;
int quarters;

quarters = amount/25;
remainder = amount%25;
dimes = amount/10;
remainder = amount%10;
remainder = remainder % 5;
return change;

}

void Write_Mixture(int quarters,int dimes, int nickels)
{


cout <<" Quarters - " <<quarters <<endl;
cout <<" Dimes - " <<dimes<<endl;
cout <<" Nickels - " <<nickels<<endl<<endl;
cout <<" Enjoy your snack!"<<endl;
cout <<" Thank you for shopping with us!"<<endl<<endl;
}


________________________________________________________________________

What in the world is wrong with it?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic