Answer on Question #40082, Programming, Other
using System;
using System.Collections.Generic;
using System.Linq;
namespace Good_Book
{
class Program
{
static void Main(string[] args)
{
String title; String publisher; int numPages; float price; String[] authors={"CK Bose"};
// authors value is CK Bose - custom value
Console.WriteLine("Enter title name:");
title = Console.ReadLine();
Console.WriteLine("Enter publisher:");
publisher = Console.ReadLine();
Console.WriteLine("Enter the number of pages:");
numPages = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter book price:");
price = (float)Convert.ToDouble(Console.ReadLine());
if (isGoodBook(title, publisher, numPages, price, authors)) Console.WriteLine("good book");
else Console.WriteLine("The book isn't good");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
static bool isGoodBook(String title, String publisher, int numPages, float price, String[] authors)
{
if (numPages < 100 || (title.ToLower())[title.Length - 1] == 's') return false;
if ((title.ToLower())[title.Length - 1] == 'e' && title.ToLower()[0] == 'a') return false;
string[] publishers = { "niho books", "dreamworldz", "pogo books", "diamond comics" };
if (!publishers.Contains<string>(publisher.ToLower())) return false;
string super_author = "CK Bose";
if (!authors.Contains<string>(super_author) && authors.Length < 3) return false;
if (authors.Contains<string>("Pran") && publisher.ToLower() != publishers[3]) return false;
if ((double)(price / numPages) * 10 < 1) return false;
return true;
}
}
}
Comments