错误& # 39;Program.Number& # 39;是'类型'But用作'变量
本文关键字:But 变量 类型 用作 Number Program 错误 | 更新日期: 2023-09-27 18:10:20
程序错误。数字'是一个'类型',但像'变量'一样使用
当我试图运行这个程序时,我一直得到上面的错误,我做错了什么
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
错误在这里:
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)
您正在切换类型Number
,必须使用Number
的实例。例如:
switch ((Number)myNumber)