c# - 当向我的程序输入值时,它会崩溃:( C#
问题描述
这是程序。有人可以告诉我我做错了什么吗?每次我为字符串 SolvingFor 输入一个值时,程序就会崩溃。我是编码新手,所以如果我犯了一个愚蠢的错误,请告诉我。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PercentageCalculator
{
class Program
{
static void Main(string[] args)
{
string SolvingFor;
int part;
int whole;
int percent;
Console.WriteLine("please only use numbers and lowercase letters.");
Console.WriteLine("Are you trying to solve for percent, part, or whole?");
SolvingFor = Convert.ToString(Console.Read());
if (SolvingFor == "part") {
Console.WriteLine("Please Enter Value of the Whole");
whole = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please Enter Value of the Percent");
percent = Convert.ToInt32(Console.ReadLine()); ;
Console.WriteLine("Your answer is" + (whole * percent) / 100); }
else if (SolvingFor == "whole")
{
Console.WriteLine("Please Enter Value of the part");
part = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please Enter Value of the Percent");
percent = Convert.ToInt32(Console.ReadLine()); ;
Console.WriteLine("Your answer is" + (part * 100) / percent);
}
else if (SolvingFor == "percent")
{
Console.WriteLine("Please Enter Value of the part");
part = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please Enter Value of the whole");
whole = Convert.ToInt32(Console.ReadLine()); ;
Console.WriteLine("Your answer is" + (part * 100) / whole);
}
else
{
Console.WriteLine("Please only input valid lowercase letters and numbers. ");
};
Console.Read();
}
}
}
解决方案
推荐阅读
- javascript - jQuery 选中/取消选中单选按钮
- java - 如何在编译时使用泛型(java)检测类差异
- vb.net - VB.net Texbox 值未更新为公共共享变量
- python - 在 Sqlite 查询中接受用户输入的条件
- foreach - SwiftUI - 尝试识别并传递被选中的列表项的值
- angular - ngx-bootstrap 在模态上将子模态居中
- python - multiprocessing.Lock 是否在其上下文中暂停程序?
- tensorflow - 如何在具有 LSTM 层的 tensorflow 集线器中使用嵌入模型?
- php - 查询 woocommerce quickview 和 oceanwp 主题
- c# - 使用 HttpResponse 在 C# 中下载具有非英文字符的文件