0

Using constants in expressions.

The question is; The cost to ship a package is a flat fee of 75 cents plus 25 cents per pound. 1. Declare a const named CENTS_PER_POUND and initialize with 25. 2. Get the shipping weight from user input storing the weight into shipWeightPounds. 3. Using FLAT_FEE_CENTS and CENTS_PER_POUND constants, assign shipCostCents with the cost of shipping a package weighing shipWeightPounds. what I have down already but the sequence isn't completed. what am I missing? #include <stdio.h> int main(void) { int shipWeightPounds; int shipCostCents = 0; const int FLAT_FEE_CENTS = 75; const int CENTS_PER_POUND = 25; shipCostCents = FLAT_FEE_CENTS + (shipWeightPounds * CENTS_PER_POUND); printf("Weight(lb): %d, Flat fee(cents): %d, Cents per pound: %d\nShipping cost(cents): %d\n", shipWeightPounds, FLAT_FEE_CENTS, CENTS_PER_POUND, shipCostCents); return 0; }

2nd Sep 2020, 5:19 PM
Manesh Divedia
Manesh Divedia - avatar
13 Réponses
+ 7
Manesh Divedia sorry i forget to paste code #include <stdio.h> int main(void) { int shipWeightPounds; int shipCostCents = 0; const int FLAT_FEE_CENTS = 75; const int CENTS_PER_POUND = 25; scanf("%d",&shipWeightPounds); shipCostCents = FLAT_FEE_CENTS + (shipWeightPounds * CENTS_PER_POUND); // scanf("%d",&shipWeightPounds); printf("Weight(lb): %d,\n Flat fee(cents): %d, \nCents per pound: %d\nShipping cost(cents): %d\n", shipWeightPounds, FLAT_FEE_CENTS, CENTS_PER_POUND, shipCostCents); return 0; }
2nd Sep 2020, 6:06 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 6
Manesh Divedia welcome sir
2nd Sep 2020, 6:09 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 5
Manesh Divedia /* try this take user input you can vary VALUEs i fixed for shipWeightPounds=10 initially. u have to take input form user i did according to your expected Output for 325. run on playground*/ #include <stdio.h> int main(void) { int shipWeightPounds=10; int shipCostCents = 0; const int FLAT_FEE_CENTS = 75; const int CENTS_PER_POUND = 25; shipCostCents = FLAT_FEE_CENTS + (shipWeightPounds * CENTS_PER_POUND); // scanf("%d",&shipWeightPounds); printf("Weight(lb): %d, Flat fee(cents): %d, Cents per pound: %d\nShipping cost(cents): %d\n", shipWeightPounds, FLAT_FEE_CENTS, CENTS_PER_POUND, shipCostCents); return 0; }
2nd Sep 2020, 5:46 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 5
run this i fixed your code according to your problm /* try this take this as a user input you can vary VALUEs i fixed for shipWeightPounds=10 initially. u have to take input form user i did according to your expected Output for 325. run on playground*/ #include <stdio.h> int main(void) { int shipWeightPounds=2201; int shipCostCents = 0; const int FLAT_FEE_CENTS = 75; const int CENTS_PER_POUND = 25; shipCostCents = FLAT_FEE_CENTS + (shipWeightPounds * CENTS_PER_POUND); // scanf("%d",&shipWeightPounds); printf("Weight(lb): %d,\n Flat fee(cents): %d, \nCents per pound: %d\nShipping cost(cents): %d\n", shipWeightPounds, FLAT_FEE_CENTS, CENTS_PER_POUND, shipCostCents); return 0; }
2nd Sep 2020, 5:50 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 4
Your this variable int shipWeightPounds is un- intilize in program so assign value.
2nd Sep 2020, 5:26 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 4
Can u tell me expected Output what u want
2nd Sep 2020, 5:34 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
the expected output is; Weight(lb): 10, Flat fee(cents): 75, Cents per pound: 25 Shipping cost(cents): 325 my output is; Weight(lb): 22061, Flat fee(cents): 75, Cents per pound: 25 Shipping cost(cents): 551600
2nd Sep 2020, 5:41 PM
Manesh Divedia
Manesh Divedia - avatar
0
how would i do that? and isnt already assigned at the top though?
2nd Sep 2020, 5:31 PM
Manesh Divedia
Manesh Divedia - avatar
0
now i got; 0 the expected output is; Weight(lb): 10, Flat fee(cents): 75, Cents per pound: 25 Shipping cost(cents): 325 my output is; Weight(lb): 10, Flat fee(cents): 75, Cents per pound: 25 Shipping cost(cents): 547100
2nd Sep 2020, 5:48 PM
Manesh Divedia
Manesh Divedia - avatar
0
i think it has to be something related to shipCostCents
2nd Sep 2020, 5:49 PM
Manesh Divedia
Manesh Divedia - avatar
0
still doesnt work https://imgur.com/ODUuk4i here look at this
2nd Sep 2020, 5:55 PM
Manesh Divedia
Manesh Divedia - avatar
0
wheres the code sorry?
2nd Sep 2020, 6:03 PM
Manesh Divedia
Manesh Divedia - avatar
0
thank you so much I truly appreciate it!!
2nd Sep 2020, 6:07 PM
Manesh Divedia
Manesh Divedia - avatar