错误'Program.Number'是'type',但用作'variable
当我尝试运行此程序时,我一直在解决上述错误
using System;
class Program
{
enum Number{ standard = 1, express = 2, same = 3};
const int A = 1, B = 2;
const int Y = 3, N = 4;
static void Main()
{
double cost, LB;
int numValues, Number_of_items ;
Console.WriteLine("please enter the type of shiping you want");
Console.WriteLine("Enter 1:standard shipping.");
Console.WriteLine("Enter 2:express shipping.");
Console.WriteLine("Enter 3:same day shipping.");
switch ((Number))
{
case Numbers.standard:
Console.WriteLine("thankyou for chooseing standerd shipping");
Console.WriteLine("please choose a catagory");
Console.Write("Type A or B to make your selection");
{ if (A==A)
{
Console.Write("please enter the number of items");
Number_of_items = int.Parse(Console.ReadLine());
cost = 3 * Number_of_items;
Console.Write("is this shipment going to alaska or Hawaii? (y or n)");
if (Y==Y)
{
cost = cost + 2.50;
Console.WriteLine("Total cost is {0}." , cost);
}
else
Console.WriteLine("total cost is {0}." , cost);
}
else
Console.Write("please enter the weiht in pounds");
LB = double.Parse(Console.ReadLine());
cost = 1.45 * LB;
Console.WriteLine("is this shipment going to alaska or Hawaii? (y or n)");
}
if (Y==Y)
{
cost = cost + 2.50;
Console.WriteLine("Total cost is {0}." , cost);
}
else
Console.WriteLine("total cost is {0}." , cost);
break;
case Numbers.express:
Console.WriteLine("thankyou for chooseing Express Shipping");
Console.WriteLine("please choose a catagory");
Console.Write("Type A or B to make your selection");
{ if (A==A)
Console.Write("please enter the number of items");
Number_of_items = int.Parse(Console.ReadLine());
cost = 4 * Number_of_items;
{
Console.Write("is this shipment going to alaska or Hawaii? (y or n)");
if (Y==Y)
{
cost = cost + 5.00;
Console.WriteLine("Total cost is {0}." , cost);
}
else
Console.WriteLine("total cost is {0}." , cost);
}
if(B==B)
Console.Write("please enter the weiht in pounds");
LB = double.Parse(Console.ReadLine());
cost = 2.50 * LB;
Console.WriteLine("is this shipment going to alaska or Hawaii? (y or n)");
}
if (Y==Y)
{
cost = cost + 5.00;
Console.WriteLine("Total cost is {0}." , cost);
}
else
Console.WriteLine("total cost is {0}." , cost);
break;
case Numbers.same:
Console.WriteLine("thankyou for chooseing Same Day Shipping");
Console.WriteLine("please choose a catagory");
Console.Write("Type A or B to make your selection");
if (A == A)
Console.Write("please enter the number of items");
Number_of_items = int.Parse(Console.ReadLine());
cost = 5.50 * Number_of_items;
Console.Write("is this shipment going to alaska or Hawaii? (y or n)");
if (Y==Y)
{
cost = cost + 8.00;
Console.WriteLine("Total cost is {0}." , cost);
}
else
Console.WriteLine("total cost is {0}." , cost);
if (B==B)
Console.Write("please enter the weiht in pounds");
LB = double.Parse(Console.ReadLine());
cost = 3.00 * LB;
Console.WriteLine("is this shipment going to alaska or Hawaii? (y or n)");
if (Y==Y)
{
cost = cost + 8.00;
Console.WriteLine("Total cost is {0}." , cost);
}
else
Console.WriteLine("total cost is {0}." , cost);
break;
}
numValues = 1;
Console.ReadLine();
}//End Main()
}//End class Program
答案 0 :(得分:1)
错误在于:
switch((Number))
我认为你要向Number
施展一些东西,但忘记了。所以我假设你的意思是:
int input;
while(!int.TryParse(Console.ReadLine(), ref input) || input < 1 || input > 3) {
Console.WriteLine("Please enter a valid option!");
}
switch((Number)input)
答案 1 :(得分:0)
您正在启用Number
类型,必须使用Number
的实例。
例如:
switch ((Number)myNumber)