I thereby only focus on the code itself, not on the streamwriter.
According to you program flow:
str = Console.ReadLine();
x = Int32.Parse(str);
for (int i = 1; i <= x; i++)
{
sw.WriteLine(10 * (i * i));
}
if (x > 10)
Console.WriteLine("Hey! The number should be 10 or less!");
else
if (x < 0)
Console.WriteLine("Hey! The number should be 0 or more!");
else
Console.WriteLine("Good job!");
Your first parsing the given value [aka the user input] and then run the calculation. Only after the calculation, it checks whether your input is between your bounds!
This has as consequence that your calculation will always run (or better spoken print) the amount of the user specified number, regardless the bound. You should use your conditional formatting earlier (that's point 1) and find a manner to let the user specify a new number between the bound.
Too bad, I am a bit sick now, otherwise I would've tried to find something for you. Hope this helps you out
Edit:
Ok, I could not resist myself to make a global thingie (despite I am sick and should rest, but I don't wanna
Anyways, I would do it in this manner:
Probably not the best way to get it all around and so on, but it does what it does. If you have questions about it, don't hesitate to ask.
[ow and I did remove your streamwrite, because I was a bit lazy, sorry >< However, you should get the general idea out of this
This post has been edited by karabasf: 19 October 2010 - 09:10 AM

New Topic/Question
Reply





MultiQuote




|