PLEASE HELP

I just started in a C++ programming class and this is only the seconds program I've written in it. I keep getting an error "warning C4244:'=' : conversion from 'double' to 'int'

THESE ARE THE DIRECTIONS

Write a C++ program to determine the final cost of a product to be purchased. The user will input: •Base price of the product
•Weight of product
•Whether the shipping destination is in-state or not
•A hazardous materials code for the product (A, B, or C only)

Your program should calculate the total cost of the product item which could include shipping and tax amounts being added on.The shipping cost will initially be based on the weight of the product item.

If weight is... Shipping cost is ...
up to 20 pounds
$14.95

at least 20, but still under 50 pounds
$19.95

50 to 100 pounds
$29.95

over 100 pounds but not over 200 pounds
$49.95

above 200 pounds
$99.95


If the product is to be shipped in-state, then there will be a 6% tax added to the base price. However, in-state shipments will receive a $10 discount on shipping. Out-of-state deliveries are charged no tax, but must pay the entire shipping charges.The hazard codes imply special shipping for hazardous materials. Additional charges are based on the code being input.

If hazard code is ... Additional shipping cost is ...

A

$0


B

$25.00


C

$50.00


Your program should include the following error-checking features:
•Base price must be above zero
•Weight must be above zero
•Hazard code must be only 'A', 'B', or 'C'
Your output should be a clear, organized summary that includes the base price, tax amount, shipping cost, and total product cost. It should be formatted to dollar amounts labels and headings as appropriate


#include <iostream>
using namespace std;
int main()
{
int productPrice, Weight, HazardCode, ShippingCost, State, FinalCost;
{
// 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): " << endl;
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;
}
Have you tried reading it?
You are assigning a integer ( number that has not a decimal part (ex.: 0 is a integer, 0.5 is a double)) to a double. By the way, you are using the incorrect data types, you are only using ints. Read this: http://www.cplusplus.com/doc/tutorial/variables/ . If you are a novice and don't know how to code, be in mind: you ALWAYS have to read. A lot.
Last edited on
I made some changes, still cant figure it out

#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;
}
When posting code, please use code tags. Highlight the code and click the <> button in the box to the right of the input window. Also, it will be easier to read your code if you indent it to follow the structure. Here is your code with tags and indented. See more comments below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#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;     // increment the
                }
                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;
}

Lines 8 & 9: weight should probably be a double. change State to a string. HazzardCode should be a char.
Line 30: You have the comparison wrong.:
Line 32: You missed weights between 100 and 200 lbs.
Line 35: I don't think you should print the shipping costs yet. It looks to me like you should print the final shipping cost, after all the adjustments.
Lines 42-49: You should adjus the shipping cost based on the hazzard code. For example:
1
2
3
if (HazardCode = 'B') {
      ShippingCost += 25.00;
}

Lines 61 & 66: strings are surrounded by double-quotes. Characters are surrounded by single quotes. So you want "Yes" and "No" instead of 'Yes' and 'No'.
Line 63: Since you're going to adjust the shipping cost based on hazzard code above, there's no need to add in the hazzard code here. Also multiplying by 0.06 gives you the tax, only, not the amount plus the tax, so you want to multiply by 1.06

Lines 62 & 67: I think these lines should actually just adjust the shipping cost based on whether it's in-state or not. Then after after all that, you should print the output.

General comment: You have a lot of unnecessary braces in the code. They highlight the structure but don't do much otherwise. It's better to highlight the structure with comments. That way you can say what each piece of code does. Better yet would be to break the pieces into separate functions. Here is the code with the extra braces removed and comments at the top of the blocks:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#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;

    // Compute base shipping cost
    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;


    // Get hazzard code and adjust shipping cost
    cout << "Please enter the Hazard Code (A, B or C): ";
    cin >> HazardCode;

    if (HazardCode = 'A') {
        HazardCode = 0; // increment the
    }
    if (HazardCode = 'B') {
        HazardCode = 25.00;
    }
    if (HazardCode = 'C') {
        HazardCode = 50.00;
    } else
        cout << "Error please ender A, B, or C" << endl;


    // Get in-state shipping and adjust shipping cost
    cout << "Are you shipping out of state? Yes or No: " << endl;
    cin >> State;

    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;
}
Topic archived. No new replies allowed.