Ending before I want it too

my program is ending before I want it to and I cant figure out why.

#include <iostream>
#include <string>
using namespace std;
int main()
{
{
int Weight, State;
double ShippingCost, HazardCode, FinalCost, productPrice;

// Collect data
{
cout << "Please enter the products price: " << endl;
cin >> productPrice;
{
if (productPrice <= 0)
cout << "Error price has to be more than 0" << endl;
}
}
{
cout << "Please enter the weight of product: " << endl;
cin >> Weight;
{
if (Weight <= 0)
{
cout << "Error weight must be over 0";
}
else if (Weight < 20)
{
ShippingCost = 14.95;
}
else if (Weight < 50)
{
ShippingCost = 19.95;
}
else if (Weight >= 100)
{
ShippingCost = 29.95;
}
else if (Weight > 200)
{
ShippingCost = 99.95;
}
cout << "Shipping cost = $ " << ShippingCost << endl;
}
}
{
cout << "Please enter the Hazard Code (A, B or C): ";
cin >> HazardCode;
{
if (HazardCode = 'A')
{
HazardCode = 0;
}
if (HazardCode = 'B')
{
HazardCode = 25.00;
}
if (HazardCode = 'C')
{
HazardCode = 50.00;
}
else
cout << "Error please ender A, B, or C" << endl;

}
}
{
{
cout << "Are you shipping out of state? Yes or No: " << endl;
cin >> State;

// Final Cost
if (State = 'Yes')
{
FinalCost = (productPrice + ShippingCost + HazardCode) * 0.06 - 10.00;
}
if (State = 'No')
{
FinalCost = productPrice + ShippingCost + HazardCode;
}
else
{
cout << "Error" << endl;
}
}
}
}

system("pause");
return 0;
}
Line 48: You're trying to enter a character into a float. That's not valid.

Line 50,54,58: You're using the assignment operator (=), not the equality operator (==).

Line 70: You're trying to enter a string into an int. Not valid.

Line 73, 77: Again you're using the assignment operator, not the equality operator.
Also, if you want to compare strings, you need to use std::string and quotes, not '.
' is for character literals.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Hint: You can edit your previous post, highlight your code and press the <> formatting button.

Please do not create multiple threads for the same problem.
http://www.cplusplus.com/forum/general/155982/#msg802648


BTW, you have way too many {} pairs. You don't need to put {} around every block of code.
Last edited on
Topic archived. No new replies allowed.