I have the following instructions for one of my labs.
program that will prompt the user for the weight and price of the produce, the price and capacity of a plastic bag and then calculates and displays the total cost of the sale. You may assume that all customers will require bags.
this is what I have so far:
string userInput;
double weight;
double price;
double capacityOfBag;
double bagPrice;
double bags;
uint numberOfBags;
uint remainder;
double cost;
Console.WriteLine("Please input the following in order to calculate the cost of sale");
Console.Write("Weight? ");
userInput = Console.ReadLine();
weight = Convert.ToDouble(userInput);
Console.Write("Price? ");
userInput = Console.ReadLine();
price = Convert.ToDouble(userInput);
Console.Write("Capacity of bag? ");
userInput = Console.ReadLine();
capacityOfBag = Convert.ToDouble(userInput);
Console.Write("Price of bag? ");
userInput = Console.ReadLine();
bagPrice = Convert.ToDouble(userInput);
bags = weight / capacityOfBag;
numberOfBags = ?????
cost = weight * price + numberOfBags * bagPrice;
Console.WriteLine($"The customer needs {numberOfBags} bags");
Console.WriteLine($"Total cost of the sale is {cost:c}");
The calculation should be simple, however, if the weight
and the capacityOfBag
are double numbers, say 24.3 and 5, then bags
would be 4.86. however, I should have 5 bags!
What would numberOfBags
be?
We haven't learned about if statements, so please don't use it in your answer, only simple math can be applied here :D
PS. Math library can't be used either.
Thanks.