Chinpoki
If statements
int textbooks;
char cover;
double rprice;
double fprice;
Console.Write("Enter the number of textbooks you wanna buy: ");
textbooks = Convert.ToInt32(Console.ReadLine());
Console.Write("Do you want premium hardcover y/n ? : ");
cover = Convert.ToChar(Console.ReadLine());
rprice = textbooks * 125;
// raw price before premium and discount
if (cover == 'y' && textbooks > 4)
{
fprice = rprice + (20 / 100 * rprice) - (5 / 100 * rprice);
}
else if (cover == 'n' && textbooks > 4)
{
fprice = rprice - (5 / 100 * rprice);
}
else if (cover == 'y' && textbooks <= 4)
{
fprice = rprice + (20 / 100 * rprice);
}
else
{
fprice = rprice;
}
Console.WriteLine("Price of " + textbooks + $" textbooks is {fprice:C}");
65 replies