What's going on here?

Well, i've been working on this for some time for class, and haven't been able to quite see what i'm doing wrong. Can any of you more experienced programmers see why this runs incorrectly?
__________________________________________________________________________
OUTPUT:
Enter base product price ($): 100
Enter product weight (lbs): 10
Hazardous Materials Code (A/B/C): A
Is the shipping in state? (y/n): 114.95Press any key to continue . . .
__________________________________________________________________________
Purpose

To build complete working C++ programs that applies variations on the selection control structure.

Specifications

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.
Design Requirement

Given variables for price, weight, hazard code, build pseudocode or C++ program code that describes your strategy for error checking. Also include pseudocode or flowchart describing your logic for calculating the shipping cost.
Deliverables

Deliver the following as your final product:

Cover page with assignment name, student name, and list of attachments
Printed copy of source code
Printed copy of output for 4 program executions using the following test cases:
Base cost: $219.95, weight 175 lbs, hazard code B, in-state.
Base cost: $29.50, weight 40 lbs, hazard code A, out-of-state.
Base cost: $518.42, weight 100 lbs, hazard code C, in-state.
Using input that demonstrates at least one required error-checking feature
Upload your source code to your student folder within the online course management system.


__________________________________________________________________________
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
//The Program will calculate the following information
	//input:
		//Product base price.
		//Product weight.
		//In/Out state shipment.
		//A, B, or C Hazardous Material.
	//output:
		//Total cost of the product:
		//Base Price + Shipping Price + Tax Price = Total Product Price

#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;

int main()

{

double base = 0, tax = 1.06, shipping = 0, T = 0, H = 0, A = 0, B = 0, C = 0, y = 0, n = 0, weight = 0, s = 0, Hout = 0;

//Base Price:
cout << "Enter base product price ($): ";
cin >> base;

//Weight Calculations:
cout << "Enter product weight (lbs): ";
cin >> weight;

if ( weight >= 0 && weight <= 19.99 )
	shipping = 14.95;
if ( weight >= 20 && weight <= 49.99 )
	shipping = 19.95;
if ( weight >= 50 && weight <= 100 )
	shipping = 29.95;
if ( weight >=100.01 && weight <= 200 )
	shipping = 49.95;
if ( weight >= 200.01 && weight <= 500 )
	shipping = 99.95;
if ( weight <= 0 )
	cout << "Invalid weight." << endl;

//Hazardous Materials Calculations:
cout << "Hazardous Materials Code (A/B/C): ";
cin >> H;
	if ( H == 'A' )
		Hout = 0;
	if ( H == 'B' )
		Hout = 25;
	if ( H == 'C' )
		Hout = 50;

//State Tax/Discount:
cout << "Is the shipping in state? (y/n): ";
cin >> s;
	if ( s == 'y' )
		T = ( base + H + shipping ) * tax - 10;
	if ( s == 'n' )
		T = ( base + H + shipping );

//Final Calculation:

//cout << "Total Price: " << base + shipping + H << endl;
T = base + shipping + Hout;
cout << setw(8) << setprecision(2) << fixed << T;

system("pause");
return 0;

}



You've declared all your input variables as doubles. You need to declare the variables T and H as type char so they will be parsed as characters by cin.
I got that!



--------------------------------------------------------------------------
http://www.rsore.com/
http://www.fifa14coinstrader.com/
Last edited on
much thanks yulingo :) !
Well it seems to get through all the prompts, but i am getting a random "r" instead of the number output?
T should not be a char, but s should.
Also,
56
57
58
59
if ( s == 'y' )
    T = ( base + H + shipping ) * tax - 10;
if ( s == 'n' )
    T = ( base + H + shipping );

I think you mean Hout instead of H in both instances here.
Topic archived. No new replies allowed.