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;
numberOfBags = Convert.ToInt32(System.Console.ReadLine());
// 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);

New Topic/Question
Reply



MultiQuote





|