Click here to Skip to main content
15,888,325 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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 tried:

#include <iostream>
using namespace std;

int main() {
   int shipWeightPounds;
   int shipCostCents = 0;
   const int FLAT_FEE_CENTS = 75;

   /* Your solution goes here  */

   cout << "Weight(lb): " << shipWeightPounds;
   cout << ", Flat fee(cents): " << FLAT_FEE_CENTS;
   cout << ", Cents per lb: " << CENTS_PER_POUND << endl;
   cout << "Shipping cost(cents): " << shipCostCents << endl;

   return 0;
}
Posted
Updated 31-Mar-22 15:06pm

..and you had a question?

Off the bat I can see you don't have one of the constants defined.
 
Share this answer
 
Comments
Zhen Gerald 1-Sep-21 17:20pm    
help me solve that question please
Dave Kreskowiak 1-Sep-21 17:21pm    
WHAT QUESTION? You haven't asked anything.
jeron1 1-Sep-21 17:28pm    
Take a close look at instruction #1.
Dave Kreskowiak 1-Sep-21 17:29pm    
I am not doing your homework for you. That is literally a single line of code.
jeron1 1-Sep-21 17:34pm    
I agree! LOL :-)
you need a function which calculates the costs like

C++
int shippingCosts( int shipWeightPounds ) {
}
Do the math yourself. And you need to declares the constants outside the main.
 
Share this answer
 
const int CENTS_PER_POUND = 25;

cin>>shipWeightPounds;

shipCostCents = FLAT_FEE_CENTS + (shipWeightPounds * CENTS_PER_POUND);


Here goes the answer I hope this helps!!
 
Share this answer
 
Comments
Dave Kreskowiak 31-Mar-22 23:53pm    
Doing someone's homework for them is not helping them, and the class is over by now.
1. Read the instructions
2. Read the code you received
3. Follow the instructions, step by step.

4. If in any of the above steps you encounter something that is not clear to you, read up on the topic in question in your course materials.

5. If and only if you've done everything of the above, and still don't understand something, formulate a question on that particular thing only.

Note: posting your entire homework assignment is not the same as asking about one particular thing that you don't understand. We cannot help you understand if you do not try to understand it first, and if you do not specify what it is that you do not understand. Solving your homework would by trivial for us, but doing so wouldn't help you understand, so it would be a waste of effort.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900