Easy question

G

Guest

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");}




}
}
}
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top