1. HELP!!! Calculation problem!

I have completed my vending machine program but returning change is not working properly. What am I doing wrong. Also when you deposit not enough change it is suppose to start over.

Here is the main, classes, and header files.

//main.cpp
#include <iostream.h>
#include <stdlib.h>
#include "candy.h"

void main()
{
int sel;
Candy c(4,50);
Chip ch(6,60);
Gum g(8,70);
double pr;

do
{
// system ("cls");
cout<<endl;
cout<<"*** Welcome to CIS-270's Candy Shop ***"<<endl
<<"To select an item enter"<<endl
<<"1. for Candy"<<endl
<<"2. for Chips"<<endl
<<"3. for Gum"<<endl
<<"9. to exit"<<endl<<endl;

cin>>sel;

while ((sel !=1) && (sel !=2) && (sel !=3)
&& (sel !=4) && (sel !=9))
{
cout << "You have made an invalid selection."
<<endl;
cin>>sel;
}
switch(sel)
{
case 1:
{
if (c.GetStock() <1)
{
cout << "Out of Stock. Please try other goods"
<< endl;
break;
}
else
{
cout <<"Please deposit:" << c.GetPrice() << "cents"
<<endl;
cin >> pr;
if (pr = c.GetPrice())
{
cout << "Collect your item at the bottom and Enjoy."
<< endl;
c.SetStock(c.GetStock()-1);
}
else if (pr > c.GetPrice())
{
cout << "Collect your item at the bottom and Enjoy.\n"
<< "Your changes is:" << pr - c.GetPrice()
<< endl;
c.SetStock(c.GetStock()-1);
}
else
cout << "Please deposit again" << endl;
break;
}
}
case 2:
{
if (ch.GetStock() <1)
{
cout << "Out of Stock. Please try other goods"
<< endl;
break;
}
else
{
cout <<"Please deposit:" << ch.GetPrice() << "cents"<<endl;
cin >> pr;
if (pr = ch.GetPrice())
{
cout << "Collect your item at the bottom and Enjoy."
<< endl;
ch.SetStock(ch.GetStock()-1);
}
else if (pr > ch.GetPrice())
{
cout << "Collect your item at the bottom and Enjoy.\n"
<< "Your changes is:" << pr - ch.GetPrice()
<< endl;
ch.SetStock(ch.GetStock()-1);
}
else
cout << "Please deposit again" << endl;
break;
}
}
case 3:
{
if (g.GetStock() <1)
{
cout << "Out of Stock. Please try other goods"
<< endl;
break;
}
else
{
cout <<"Please deposit:" << g.GetPrice() << "cents"<<endl;
cin >> pr;
if (pr = g.GetPrice())
{
cout << "Collect your item at the bottom and Enjoy."
<< endl;
g.SetStock(g.GetStock()-1);
}
else if (pr > g.GetPrice())
{
cout << "Collect your item at the bottom and Enjoy.\n"
<< "Your changes is:" << pr - g.GetPrice()
<< endl;
g.SetStock(g.GetStock()-1);
}
else
cout << "Please deposit again" << endl;
break;
}
}
case 4:
{
if (co.GetStock() <1)
{
cout << "Out of Stock. Please try other goods"
<< endl;
break;
}
else
{
cout <<"Please deposit:" << co.GetPrice() << "cents"<<endl;
cin >> pr;
if (pr = co.GetPrice())
{
cout << "Collect your item at the bottom and Enjoy."
<< endl;
co.SetStock(co.GetStock()-1);
}
else if (pr > co.GetPrice())
{
cout << "Collect your item at the bottom and Enjoy.\n"
<< "Your changes is:" << pr - co.GetPrice()
<< endl;
co.SetStock(co.GetStock()-1);
}
else
cout << "Please deposit again" << endl;
break;
}
}
case 9:
{
cout<<"Goodbye"<<endl;
break;
}
}
}while(sel !=9);
}

//candy.cpp
#include <iostream.h>
#include "candy.h"

Candy::Candy(int i, double d)
{
price = d;
stock = i;
}

Chip::Chip(int i, double d)
{
price = d;
stock = i;
}

Gum::Gum(int i, double d)
{
price = d;
stock = i;
}

{
price = d;
stock = i;
}

void Candy::SetStock(int i)
{
stock = i;
}

int Candy::GetStock()
{
return stock;
}

double Candy::GetPrice()
{
return price;
}

void Chip::SetStock(int i)
{
stock = i;
}

int Chip::GetStock()
{
return stock;
}

double Chip::GetPrice()
{
return price;
}

void Gum::SetStock(int i)
{
stock = i;
}

int Gum::GetStock()
{
return stock;
}

double Gum::GetPrice()
{
return price;
}

{
stock = i;
}

{
return stock;
}

{
return price;
}

//candy.h
class Candy
{
private:
int stock;
double price;
public:
Candy(int,double);
int GetStock();
void SetStock(int);
double GetPrice();
};

class Chip
{
private:
int stock;
double price;
public:
Chip(int,double);
void SetStock(int);
int GetStock();
double GetPrice();
};

class Gum
{
private:
int stock;
double price;
public:
Gum(int,double);
int GetStock();
void SetStock(int);
double GetPrice();
};

{
private:
int stock;
double price;
public:
int GetStock();
void SetStock(int);
double GetPrice();
};

2. If you want to compare use the == operator and not the = operator:
Code:
`if (pr = c.GetPrice())`
Change it to:
Code:
`if (pr == c.GetPrice())`

3. and please use code tags!

4. Thanks!!!
......and sorry about not putting any tags.