运行程序时,即使我输入no,它也会添加75.我不知道它为什么要这么做.我对此还是个新手.
Console.WriteLine("Do you smoke? (Y/N)");
SmokerStatus = Console.ReadLine();
if (SmokerStatus != "y" || SmokerStatus != "Y" || SmokerStatus != "yes" || SmokerStatus != "Yes")
{
BaseQuote = BaseQuote + Convert.ToInt32(75);
}
else if (SmokerStatus != "n" || SmokerStatus != "N" || SmokerStatus != "no" || SmokerStatus != "No")
{
BaseQuote = BaseQuote - Convert.ToInt32(100);
}
这是完整的节目,我有同样的问题与条件状态部分.在那两个部分之前,一切都运行得很好.
using System;
using System.Collections;
namespace Insurance
{
internal class Insurance
{
public static void Main(string[] args)
{
Console.WriteLine("Nationwide Heath Insurance Co.\n");
#pragma warning disable CS0168
#pragma warning disable CS0165
#pragma warning disable CS8600
#pragma warning disable CS8321
#pragma warning disable CS0219
#pragma warning disable CS8601
int CustomerID = 1;
int Age;
decimal BaseQuote = 250;
String Eir, Gender, FirstName, LastName, UserAge, ConditionStatus, BadConditions, SmokerStatus;
bool ConditionBool;
decimal CoverageAmount, BasePremiumRate, AgePremiumFactor,
SmokingPremiumFactor, HealthConditionFactor, TotalPremium;
Console.WriteLine("Please enter your first name:");
FirstName = Console.ReadLine();
Console.WriteLine("Please enter your last name ");
LastName = Console.ReadLine();
Console.WriteLine("Please enter your gender ");
Gender = Console.ReadLine();
if (Gender != "male" || Gender != "Male" || Gender != "m" || Gender != "M")
{
BaseQuote = BaseQuote + Convert.ToInt32(250);
}
else if (Gender != "female" || Gender != "Female" || Gender != "f" || Gender != "F")
{
BaseQuote = BaseQuote + Convert.ToInt32(175);
}
Console.WriteLine("Please enter your age");
UserAge = Console.ReadLine();
Age = Convert.ToInt32(UserAge);
if (Age < 35)
{
BaseQuote = BaseQuote + Convert.ToInt32(50);
}
else if (Age > 35 && Age < 55)
{
BaseQuote = BaseQuote + Convert.ToInt32(100);
}
else if (Age > 55 && Age < 70)
{
BaseQuote = BaseQuote + Convert.ToInt32(162.5);
}
else if (Age >= 70)
{
Console.WriteLine("No Quote Provided");
Environment.Exit(0);
}
Console.WriteLine("Please enter your adress (eircode)");
Eir = Console.ReadLine();
#pragma warning disable CS8602
Eir = Eir.ToUpper();
Console.WriteLine("Do you have an existing health conditions? (Y/N)");
ConditionStatus = Console.ReadLine();
if (ConditionStatus != "y" || ConditionStatus != "Y" || ConditionStatus != "yes" || ConditionStatus != "Yes")
{
BaseQuote = BaseQuote + Convert.ToInt32(125);
}
else if (ConditionStatus != "n" || ConditionStatus != "N" || ConditionStatus != "no" || ConditionStatus != "No")
{
BaseQuote = BaseQuote + Convert.ToInt32(0);
}
Console.WriteLine("Please list conditions using comas. If none then type 'None' or 'NA'");
BadConditions = Console.ReadLine();
Console.WriteLine("Do you smoke? (Y/N)");
SmokerStatus = Console.ReadLine();
if (SmokerStatus != "y" || SmokerStatus != "Y" || SmokerStatus != "yes" || SmokerStatus != "Yes")
{
BaseQuote = BaseQuote + Convert.ToInt32(75);
}
else if (SmokerStatus != "n" || SmokerStatus != "N" || SmokerStatus != "no" || SmokerStatus != "No")
{
BaseQuote = BaseQuote - Convert.ToInt32(100);
}
/* string BadConditions = "Do you have any existing health conditions? ( y/n )";
Console.WriteLine(BadConditions);
ConditionBool = AskCondition(ref BadConditions); */
Console.WriteLine($"Quote ID: {CustomerID}\n");
Console.WriteLine($"Name: {FirstName} {LastName}");
Console.WriteLine($"Age: {Age}");
Console.WriteLine($"Gender: {Gender}");
Console.WriteLine($"Address: {Eir}");
Console.WriteLine($"Health Conditions: {BadConditions}");
Console.WriteLine($"Quote: {BaseQuote}");
}
/* private static bool AskCondition(ref string BadConditions)
{
bool ConditionBool;
while (true)
{
string ConditionAnswer = Console.ReadLine();
if (ConditionAnswer != null && ConditionAnswer == "y")
{
ConditionBool = true;
Console.WriteLine("Please specify your health condition using a coma:");
BadConditions = Console.ReadLine();
string[] HealthConditions = new string[] { "" };
HealthConditions = BadConditions.Split(',');
break;
}
else if (ConditionAnswer != null && ConditionAnswer == "n")
{
ConditionBool = false;
break;
}
else
{
Console.WriteLine("Only y or n Allowed");
}
}
return ConditionBool;
} */
}
}