using System;
namespace Toy_Shop
{
class Program
{
static void Main(string[] args)
{
//pricing of the toys in the toy shop
const double puzzlePrice = 2.60;
const double dollPrice = 3.00;
const double teddyBearPrice = 4.10;
const double minionPrice = 8.20;
const double toyTruckPrice = 2.00;
//vacationPrice is the amount Petya needs to go on a vacation
//the rest is the amount of each toy thta has been ordered
double vacationPrice = double.Parse(Console.ReadLine());
int puzzlesSold = int.Parse(Console.ReadLine());
int dollsSold = int.Parse(Console.ReadLine());
int teddyBearsSold = int.Parse(Console.ReadLine());
int minionsSold = int.Parse(Console.ReadLine());
int toyTrucksSold = int.Parse(Console.ReadLine());
int totalToys = puzzlesSold + dollsSold + teddyBearsSold + minionsSold + toyTrucksSold;
double total = puzzlesSold * puzzlePrice + dollsSold * dollPrice + teddyBearsSold * teddyBearPrice + minionsSold * minionPrice + toyTrucksSold * toyTruckPrice;
if(totalToys >= 50)
{
double totalWithDiscount = total - (total * 0.25);
double finalIncome = totalWithDiscount - (totalWithDiscount * 0.1);
bool vacation = finalIncome > vacationPrice;
double moneyNeeded = (finalIncome - vacationPrice) * -1;
if(vacation)
Console.WriteLine($"Yes! {finalIncome - vacationPrice} lv left.");
else
Console.WriteLine($"Not enough money! {moneyNeeded} lv needed");
}
else
{
double finalIncome = total - (total * 0.1);
bool vacation = finalIncome > vacationPrice;
double moneyNeeded = (finalIncome - vacationPrice) * -1;
if (vacation)
Console.WriteLine($"Yes! {finalIncome - vacationPrice} lv left.");
else
Console.WriteLine($"Not enough money! {moneyNeeded} lv needed");
}
}
}
}
Asked
Active
Viewed 417 times
0

IndieGameDev
- 2,905
- 3
- 16
- 29

Temix
- 1
-
Does this answer your question? [How do you round a number to two decimal places in C#?](https://stackoverflow.com/questions/257005/how-do-you-round-a-number-to-two-decimal-places-in-c) – IndieGameDev Oct 10 '20 at 12:05
2 Answers
1
static void Main(string[] args)
{
float value = 145.352f;
Console.WriteLine(string.Format("Number are: {0:N2} ", value));
Console.ReadKey();
}
// Output: Number are: 145,35
More info Standard numeric format strings

Mauricio Kenny
- 93
- 6
-
@Temix: please note that thanks is expressed by upvoting and/or marking as answer – Stefan Oct 10 '20 at 12:36
-
Or preferably with string interpolation like used in the question: `Console.WriteLine($"Number are: {value:N2}");` – ckuri Oct 10 '20 at 12:47
-
You don't need `string.Format` here. `Console.Writeline` expects the same type of parameters (a format string with placeholders and the objects to format). So `Console.WriteLine("Number is {0:N2}", value);` will produce equivalent results with one less function call (the added `string.Format`) That aside, interpolation as suggested by the other comment would work as well. – pinkfloydx33 Oct 10 '20 at 13:31
-
Of course it's not necessary string.Format. It's just one more option. – Mauricio Kenny Oct 10 '20 at 13:38
0
// val = 1234.5678
Console.WriteLine(val.ToString("N2"));//1234.56
// Or
Console.WriteLine(Math.Round(val, 2));//1234.56

Usama Safi
- 151
- 8