我试图做一件简单的事情,但它给了我一个错误。错误是:
使用未分配的局部变量“answer”
我哪里做错了?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int l;
int w;
int h;
Console.WriteLine("Please Enter th points");
Console.Write("Length: ");
l = int.Parse(Console.ReadLine());
Console.Write("Width: ");
w = int.Parse(Console.ReadLine());
Console.Write("Height: ");
h = int.Parse(Console.ReadLine());
int answer;
Console.WriteLine("Enter what you want to Do [S,P,V]");
string cupSize = Console.ReadLine();
switch (cupSize)
{
case "s":
answer = (l * w);
break;
case "S":
answer = (l * w);
break;
case "p":
answer = ((l + w) * 2);
break;
case "P":
answer = ((l + w) * 2);
break;
case "v":
answer = (l * w * h);
break;
case "V":
answer = (l * w * h);
break;
default:
Console.WriteLine("Try agian");
break;
}
if (answer != 0)
{
Console.WriteLine("The answer is " + answer );
}
}
}
}