|
-
October 20th, 2009, 10:45 PM
#1
Program help please!
Hi guys, I am new to C++ and I am told to write this program but I do not know where to start. I am suppose to write a program that does this..
Write a program that asks for the weight of the package and the distance it is to be shipped, and then display the charges. When calculating the rate, drop fractions of miles, then add one for each whole or partial segment of 500 miles.
^ what does add one for each whole or partial segment of 500 miles mean?
weight of package =2 kg or less, rate per 500 miles shipped = $1.10
weight of package =over 2kg but less than 6kg , rate per 500 miles shipped = $2.20
weight of package =over 6kg but less than 10kg , rate per 500 miles shipped = $3.70
weight of package =over 10kg but less than 20kg , rate per 500 miles shipped = $4.80
Please help guys..I am really stuck
Last edited by Sabensohn70; October 20th, 2009 at 10:48 PM.
-
October 20th, 2009, 11:38 PM
#2
-
October 21st, 2009, 07:14 AM
#3
Re: Program help please!
Well, looks like:
0-499 miles, -> 1
500-999 miles -> 2
1000-1999 miles -> 3, etc.
Multiply your 'Weight Rate' by your 'shipping distance value' (1, 2, 3, ... above).
Show result. Done.
Hint, the modulus operator might help you out in determining how many multiples of 500 miles you have.
-
October 21st, 2009, 08:48 AM
#4
Re: Program help please!
Sabensohn70: What part of task are you struggling to complete? Please show us your code and any error messages you may receive.
Before post, make an effort yourself, try googling or search here.
When posting, give a proper description of your problem, include code* and error messages.
*All code should include code tags
-
October 21st, 2009, 11:26 AM
#5
Re: Program help please!
what does add one for each whole or partial segment of 500 miles mean?
The rate is calculated in increments of 500 miles. Therefore 500 miles is one unit. If the package needs to be shipped 520 miles, then you have to charge them (rate*2) where the rate is determined by the weight. If the distance is 1050.7 miles, you charge (rate*3). The fraction really doesn't matter so it can be dropped or the original distance can be cast into an integer to get rid of it. If distance is 500.7 miles, it sounds like you are supposed to drop the fraction first and charge (rate*1). You'll have to figure out how to read in the data and perform some simple calculations to determine the rate based on weight. then you'll have to calculate the number of distance units and muliply (rate*distanceSegments).
-
October 21st, 2009, 01:44 PM
#6
Re: Program help please!
Code:
cout<<"GIMME DA WEIGHT"<<endl;
cin>> weight;
cout<<"GIMME DA MILES"<<endl;
cin>> miles;
chargedMiles= miles/500;
/* round "chargedMiles" UP */
costs;
if(weight<= 2)
costs= chargedMiles * 1.1;
else if(weight<6)
costs= chargedMiles * 2.2;
else if(weight<10
costs= chargedMiles * 3.7;
does this help?
-
October 22nd, 2009, 02:43 AM
#7
Re: Program help please!
the thing is one of the inputs has to be 10 for distance so 10/500 * 1.10 = 0.022, but the desired answer is 1.10.
ok guys here is my full task and my code.
"Write a program that asks for the weight of the package and the distance it is to be shipped, and then displays its charges. When calculating the rate, drop fractions of miles, then add one for each whole or partial segment of 500 miles."
this is my code so far and there is the same "if"s for all the different weights (weight 2 kg but no more than 6, 6 kg but no more than 10 etc etc)..
Code:
float weight, distance rate, shipcharge;
cout << " gimme package weight:";
cin >> weight;
count << "gimme distance:";
cin >> distance;
if (weight <=2)
{
if ( distance <= 500)
shipcharge= 1.10 * 1
else if (distance > 500 && distance <= 1000)
shipcharge = 1.10 * 2
else if (distance >1000 && distance <= 1500)
-
October 22nd, 2009, 01:30 PM
#8
-
October 22nd, 2009, 01:32 PM
#9
Re: Program help please!
 Originally Posted by Sabensohn70
anybody?
Ask a question so we can help you.
And you should post your actual compilable code.
-
October 22nd, 2009, 01:34 PM
#10
Re: Program help please!
You shouldn't be doing this with if/else if. The assignment is asking you to come up with a computational formula which will give you the rate regardless of distance.
I'll point out a few key phrases:
This means that you'll need to apply the floor() function.
each whole or partial segment of 500 miles
This implies a division followed by the ceil() function.
-
October 22nd, 2009, 01:35 PM
#11
Re: Program help please!
that is my code so far. my question is what am i suppose to do for the "when calculating the rate, drop fractions of miles and add one for each whole or partial segment of 500 miles".
EDIT: Oh, but i have not learned the floor function or the ceil function in class yet..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|