# Writing a program that increments by a certain amount.

I try to write a program that will get the weight and then calculate the cost. If <=16 ounces, cost is \$3.00 (in this format). If >16 the cost increases for each increment of 4 ounces by .50. Can someone tell me what is wrong with my coding. The program give me a cost of 3 when I input a weight <16 but it gives me a negative number for weights >16.

#include
#include
#include

int main()
{
int wgt;
int x=0;
double cost;
int n = 4;
double i = 0.50;
double y;

cout <<"Enter the weight" <<endl;
cin >> wgt;

if (wgt <16)
cost = 3.00;

cout <<"The cost is" <<cost <<endl;
{
if
(wgt >16)
wgt = wgt +x;
x= n++;
y= i++;
cost = cost +y;

cout <<"Do you want to calculate the delivery";
cout <<" cost for another package?" <<endl;
}
return 0;

}

• : I try to write a program that will get the weight and then calculate the cost. If <=16 ounces, cost is \$3.00 (in this format). If >16 the cost increases for each increment of 4 ounces by .50. Can someone tell me what is wrong with my coding. The program give me a cost of 3 when I input a weight <16 but it gives me a negative number for weights >16.
:
:
: #include
: #include
: #include
:
: int main()
: {
: int wgt;
: int x=0;
: double cost;
: int n = 4;
: double i = 0.50;
: double y;
:
: cout <<"Enter the weight" <<endl;
: cin >> wgt;
:
: if (wgt <16)
: cost = 3.00;
:
: cout <<"The cost is" <<cost <<endl;
: {
: if
: (wgt >16)
: wgt = wgt +x;
: x= n++;
: y= i++;
: cost = cost +y;
:
:
: cout <<"Do you want to calculate the delivery";
: cout <<" cost for another package?" <<endl;
: }
: return 0;
:
: }
:
:
Your positioning of {} make no sense at all. The only pair you have at the moment are redundant, since they do not belong to either if statement.

Somewhere, you need to have
[code]
if ( wgt < 16 ) {
// do something
} else {
// do something else
}
cout <<"The cost is" <<cost <<endl;
[/code]