简单的问题 [英] Easy question
问题描述
我做的第一次工作,但第二次打破了
len = Convert.ToDouble(Console.ReadLine());
它说我有一个未处理的系统格式异常。帮助!
使用System;
使用System.Text;
名称空间赋值1
{< br $>
///< summary>
/// Class1的摘要说明。
///< / summary>
class Assignment1
{
///< summary>
///应用程序的主要入口点。
///< / summary>
[STAThread]
static void Main(string [] args)
{
矩形rect =新矩形();
双len,宽;
int any;
bool选项;
do
{
Console.Write("输入矩形长度:");
len = Convert.ToDouble(Console.ReadLine());
Console.Write(" \\\
Enter矩形宽度:");
wide = Convert.ToDouble(Console.ReadLine());
rect.assign(len,wide);
控制台。写(Rectangle length =" + rect.getLength()+ \ n");
Console.Write(" width =" + rect.getWidth()+" \ n");
Console.Write(" area =" + rect.getArea()+" \ n");
Console.Write(\ n你要继续吗?输入1继续,2输入
停止:");
any = Console.Read();
if(any ==''1'')
option = true;
else
option = false;
}
while(option);
// for(int i = 0; i< 50; i ++)
// {Console.Write(" \ n DSorry但你需要有一个循环结构来
完成此操作);}
for(int i = 0; i< 50; i ++)
{Console.Write(" \\ \\ n哦,下次见到你);}
}
}
}
My do while works the first time but the second time it breaks at the
len = Convert.ToDouble(Console.ReadLine());
It says that I have an unhandled System format exception. Help!
using System;
using System.Text;
namespace assignment1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Assignment1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
rectangle rect = new rectangle();
double len, wide;
int any;
bool option;
do
{
Console.Write("Enter length of rectangle: ");
len = Convert.ToDouble(Console.ReadLine());
Console.Write("\nEnter width of rectangle: ");
wide = Convert.ToDouble(Console.ReadLine());
rect.assign(len, wide);
Console.Write("Rectangle length = " +rect.getLength() + "\n");
Console.Write(" width =" + rect.getWidth() + "\n");
Console.Write(" area =" + rect.getArea() + "\n");
Console.Write("\n Do you want to continue? Type 1 to continue, 2 to
stop: ");
any = Console.Read();
if (any == ''1'')
option = true;
else
option = false;
}
while (option);
// for(int i = 0; i < 50; i++)
// {Console.Write("\n DSorry but you need to have a loop structure to
accomplish this");}
for(int i = 0; i < 50; i++)
{Console.Write("\n Oh well see you next time");}
}
}
}
推荐答案
从外观上看,问题出在你的行中:
any = Console .Read();
而不是只接受一个特征呃,它迫使你按回车键,
,我怀疑它是由下一个ReadLine()部分处理的,当它看起来像是b $ b。一个选项是将any = Console.Read()更改为any =
Console.ReadLine(),它将以相同的方式工作,只有它不会打破
秒时间过去了。
布兰登
" Rachel"写道:
From the looks of it, the problem lies in your line:
any = Console.Read();
Rather than accept only a single character, it forces you to press enter,
which I suspect is being partially handled by the next ReadLine() when it
looks. One option is to change any = Console.Read() to any =
Console.ReadLine() which would work the same way, only it would not break the
second time through.
Brendan
"Rachel" wrote:
我的第一次工作,但第二次它在
len = Convert.ToDouble(Console.ReadLine());
它说我有一个未处理的系统格式异常。帮助!
使用System;
使用System.Text;
命名空间赋值1
{
///< summary>
/// Class1的摘要描述。
///< / summary>
class Assignment1
{
///< summary>
// /应用程序的主要入口点。
///< / summary>
[STAThread]
static void Main(string [] args)
{
rectangle rect = new rectangle();
double len,wide;
int any;
bool选项;
做
{
控制台.Write("输入矩形的长度:");
len = Convert.ToDouble(Console.ReadLine());
Console.Write(" \\\
Enter width of rectangle:");
wide = Convert.ToDouble(Console.ReadLine());
rect.assign(len,wide);
Console.Write(" Rectangle length =" + rect.getLength()+" \\\
");
Console.Write(" width =" + rect.getWid th()+" \ n");
Console.Write(" area =" + rect.getArea()+" \ n");
Console.Write(\ n你想继续吗?类型1继续,2到
停止:");
any = Console.Read();
if(any ==''1'')
option = true;
else
选项= false;
}
while(选项);
// for(int i = 0; i< 50; i ++)
// {控制台。写(\ n DSorry,但你需要有一个循环结构才能完成这个);}
for(int i = 0; i< 50; i ++)
{Console.Write(&#; n哦,下次见到你);}
}
}
}
My do while works the first time but the second time it breaks at the
len = Convert.ToDouble(Console.ReadLine());
It says that I have an unhandled System format exception. Help!
using System;
using System.Text;
namespace assignment1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Assignment1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
rectangle rect = new rectangle();
double len, wide;
int any;
bool option;
do
{
Console.Write("Enter length of rectangle: ");
len = Convert.ToDouble(Console.ReadLine());
Console.Write("\nEnter width of rectangle: ");
wide = Convert.ToDouble(Console.ReadLine());
rect.assign(len, wide);
Console.Write("Rectangle length = " +rect.getLength() + "\n");
Console.Write(" width =" + rect.getWidth() + "\n");
Console.Write(" area =" + rect.getArea() + "\n");
Console.Write("\n Do you want to continue? Type 1 to continue, 2 to
stop: ");
any = Console.Read();
if (any == ''1'')
option = true;
else
option = false;
}
while (option);
// for(int i = 0; i < 50; i++)
// {Console.Write("\n DSorry but you need to have a loop structure to
accomplish this");}
for(int i = 0; i < 50; i++)
{Console.Write("\n Oh well see you next time");}
}
}
}
这篇关于简单的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!