# An order program where I need to sort the order into boxes?

Page 1 of 1

## 8 Replies - 1117 Views - Last Post: 03 December 2012 - 10:24 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=301579&amp;s=b51fe9e4a725845ce18ac56867892f99&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Charizarzar

Reputation: 0
• Posts: 3
• Joined: 25-November 12

# An order program where I need to sort the order into boxes?

Posted 25 November 2012 - 05:24 PM

I'm having some issues with a program I'm trying to create.
I'm very much a beginner, so forgive me if the solution is very easy to figure out. I'm just learning as I go along. But I'm struggling with this one.
I'm working out the total cost for an order which a customer makes. There are 3 types of boxes that come with the order. boxes come in three sizes: the large box holds twenty 2-lb bags, the medium 10 bags, and the small 5 bags. The cost of a large box is £2.00; a medium box is £1.50; and a small box is £1.00. I've calculated the total cost of the order, but I'm struggling with the last part where I'm trying to split up the number of boxes needed and the cost of each of the boxes. E.g. When I type in 52 orders I should get 2 large boxes (£4.00), 1 medium (£1.50) and 1 small (£1.00). This is from my own working out
My problem is that I'm unsure of what code I actually need to split the boxes up. At the moment my code is just calculating the total number of large, medium and small boxes that will hold the order without (from the example) taking 20 bags away from the order once it realises that is has used up two large boxes.
I've included my code so that you can see what the program is about and what I have done so far:
// 1.   Display a friendly header
System.Console.WriteLine("\t\t\tTeaTime Order Cost Calculation Program");
System.Console.WriteLine("\t\t\t--------------------------");

System.Console.WriteLine();

// 2.	Display prompt to enter number of bags ordered
System.Console.Write("Please enter the number of bags of tea ordered> ");
// 3.	Input number and store in numberOfBags
int numberOfBags;

// 6.   Compute order cost
double orderCost = numberOfBags * 7.50;
// 7.   Compute amount of large boxes
double numberLargeBoxes = numberOfBags / 20;

// 6.	Compute amount of medium boxes
double numberMediumBoxes = numberOfBags / 10;

// 7.   Compute amount of small boxes
double numberSmallBoxes = numberOfBags / 5;

// 8.   Compute cost of large boxes
double costLargeBoxes = numberLargeBoxes * 2.00;

// 9.   Compute cost of medium boxes
double costMediumBoxes = numberMediumBoxes * 1.50;

// 10.  Compute cost of small boxes
double costSmallBoxes = numberSmallBoxes * 1.00;

// 12.  Compute total order cost
double totalCost = orderCost + costLargeBoxes + costMediumBoxes + costSmallBoxes;
System.Console.WriteLine();

// 9.    Display number of bags ordered
System.Console.WriteLine("Number of bags ordered: {0:00} ", numberOfBags);

// 10.   Display order cost
System.Console.WriteLine("Order cost: £{0:0.00} ", orderCost);

// 11.   Display amount of large boxes
System.Console.WriteLine("Boxes used:");
System.Console.WriteLine("{0:0} large", numberLargeBoxes);

// 12. Display cost of large boxes
System.Console.WriteLine("£{0:00}", costLargeBoxes);

// 13.	Display amount of medium boxes
System.Console.WriteLine("{0:0} medium", numberMediumBoxes);

// 14.  Display cost of medium boxes
System.Console.WriteLine("£{0:00}", costMediumBoxes);

// 15.  Display amount of small boxes
System.Console.WriteLine("{0:0} small", numberSmallBoxes);

// 16.  Display cost of small boxes
System.Console.WriteLine("£{0:00}", costSmallBoxes);

// 17. Display total cost
System.Console.WriteLine("Your total order cost is: £{0:00}", totalCost);

Is This A Good Question/Topic? 0

## Replies To: An order program where I need to sort the order into boxes?

### #2 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6528
• Posts: 14,438
• Joined: 02-June 10

## Re: An order program where I need to sort the order into boxes?

Posted 25 November 2012 - 07:18 PM

1 - Don't use double for money. It is prone to rounding errors. use decimal instead. Just do a find/replace for double and replace with decimal.

2 - What exactly is your question? Maybe I just missed it, but the closest I could find was:

Quote

My problem is that I'm unsure of what code I actually need to split the boxes up.
Which seems very much like

Quote

Would someone figure out my logic for me.

### #3 Momerath

• D.I.C Lover

Reputation: 1020
• Posts: 2,463
• Joined: 04-October 09

## Re: An order program where I need to sort the order into boxes?

Posted 26 November 2012 - 12:34 AM

A hint: You need to remove the items that are already in boxes.

### #4 Charizarzar

Reputation: 0
• Posts: 3
• Joined: 25-November 12

## Re: An order program where I need to sort the order into boxes?

Posted 26 November 2012 - 06:11 AM

tlhIn`toq, on 25 November 2012 - 07:18 PM, said:

1 - Don't use double for money. It is prone to rounding errors. use decimal instead. Just do a find/replace for double and replace with decimal.

2 - What exactly is your question? Maybe I just missed it, but the closest I could find was:

Quote

My problem is that I'm unsure of what code I actually need to split the boxes up.
Which seems very much like

Quote

Would someone figure out my logic for me.

Basically it's a program where the user can order 2lb bags of tea. So if they order 58 bags, it will take 2 large boxes, 1 medium box and 2 small boxes. (Remember the large boxes can hold 20 2lb bags of tea, the medium can hold 10 and the small can hold 5.) The boxes are just for packaging. So at the end it will display the total cost once it has added up the cost of the order and the cost of the packaging. I drew this up if this explains it better:
TeaTime order cost calculation program
--------------------------------------

Please enter the number of bags of tea ordered> 52

Number of bags Ordered: 52 - £390.00

Boxes Used:
2 Large - £4.00
1 Medium - £1.50
1 Small - £1.00

Your total order cost is: £396.50

I forgot to mention that the price of each 2lb bag is £7.50
The cost of the large box is £2.00
The medium is £1.50
The small is £1.00

### #5 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6528
• Posts: 14,438
• Joined: 02-June 10

## Re: An order program where I need to sort the order into boxes?

Posted 26 November 2012 - 07:30 AM

What is your question to us? If you are asking "How do I get started? How do I plan this out?" then read the Homework help article linked in my signature block.

If that isn't your question, then I for one am totally missing it.

### #6 Momerath

• D.I.C Lover

Reputation: 1020
• Posts: 2,463
• Joined: 04-October 09

## Re: An order program where I need to sort the order into boxes?

Posted 26 November 2012 - 07:45 AM

Charizarzar, on 25 November 2012 - 05:24 PM, said:

My problem is that I'm unsure of what code I actually need to split the boxes up. At the moment my code is just calculating the total number of large, medium and small boxes that will hold the order without (from the example) taking 20 bags away from the order once it realises that is has used up two large boxes.

The problem and the solution from the original post. Since the original poster has already done such complex math as multiplication, I'm not sure why subtraction is giving them such issues.

### #7 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6528
• Posts: 14,438
• Joined: 02-June 10

## Re: An order program where I need to sort the order into boxes?

Posted 26 November 2012 - 07:57 AM

"I'm unsure of what code I need" - pretty much says "I don't know what to write" or "Can someone figure out my logic for me?"

I don't think the OP's problem is with doing subtraction per-sae. I think the problem is they can't envision the algorithm of the work.

Quote

without (from the example) taking 20 bags away from the order once it realises that is has used up two large boxes.

I agree that this just screams "Well then subtract the 20 bags from the order." As you said, they had not problem with any of the rest of the more complex stuff but can't do the subtraction? Makes one wonder how much of the code the OP actually wrote on their own.

### #8 Charizarzar

Reputation: 0
• Posts: 3
• Joined: 25-November 12

## Re: An order program where I need to sort the order into boxes?

Posted 03 December 2012 - 04:10 AM

tlhIn`toq, on 26 November 2012 - 07:57 AM, said:

"I'm unsure of what code I need" - pretty much says "I don't know what to write" or "Can someone figure out my logic for me?"

I don't think the OP's problem is with doing subtraction per-sae. I think the problem is they can't envision the algorithm of the work.

Quote

without (from the example) taking 20 bags away from the order once it realises that is has used up two large boxes.

I agree that this just screams "Well then subtract the 20 bags from the order." As you said, they had not problem with any of the rest of the more complex stuff but can't do the subtraction? Makes one wonder how much of the code the OP actually wrote on their own.

I wrote all of the code on my own. I know my basic templates for coding but I'm a beginner and struggle with concepts that more advanced programmers would find easy. But thanks for that. Shows how much of a support site this really is.

Charizarzar, on 03 December 2012 - 04:08 AM, said:

tlhIn`toq, on 26 November 2012 - 07:57 AM, said:

"I'm unsure of what code I need" - pretty much says "I don't know what to write" or "Can someone figure out my logic for me?"

I don't think the OP's problem is with doing subtraction per-sae. I think the problem is they can't envision the algorithm of the work.

Quote

without (from the example) taking 20 bags away from the order once it realises that is has used up two large boxes.

I agree that this just screams "Well then subtract the 20 bags from the order." As you said, they had not problem with any of the rest of the more complex stuff but can't do the subtraction? Makes one wonder how much of the code the OP actually wrote on their own.

I wrote all of the code on my own. I know my basic templates for coding but I'm a beginner and struggle with concepts that more advanced programmers would find easy. But thanks for that. Shows how much of a support site this really is.
My question was simply to ask where I had gone wrong, because I had run the program and it hadn't worked. I included the code to be as helpful as I possibly could as well as the scenario. I imagine I'd have to put an if statement but I literally have no clue about what to do with them.

### #9 Momerath

• D.I.C Lover

Reputation: 1020
• Posts: 2,463
• Joined: 04-October 09

## Re: An order program where I need to sort the order into boxes?

Posted 03 December 2012 - 10:24 AM

The answer to your problem was posted multiple times. What more do you want?