473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Easy question

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


}
}
}

Nov 17 '05 #1
1 1414
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:
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");}


}
}
}

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: rdsteph | last post by:
I am having a lot of fun using the pyGoogle module ( http://pygoogle.sourceforge.net/ ) that uses the Google API. It is about as easy to use as I can imagine, and it is a lot nicer than using my...
5
by: LedZep | last post by:
What up, All I need to do is enter a last name in a text box, query a MSAccess database and display the name with the corresponding columns. This is no problem, but when there are more than one...
13
by: Ghislain Tanguay | last post by:
I have a compiled vb.net app and I want to give the user a choice to launch it from the start line command and pass it a parameter or not. How can I do that in my code? Is it possible? Ex. :...
1
by: melanieab | last post by:
Hi, If there's a textbox and the text entered is longer than what's visible (the textbox length), how do you make it so that the beginning chunk of text is visible (instead of the last part of...
6
by: Martin Bootsma | last post by:
I have a C question, which looks very easy, but no one here seems to know an easy answer. I have a function "powell" (from Numerical Recipes) which takes an argument of the type "double...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.