-
August 28th, 2012, 03:43 AM
#1
A noob doing lots of things wrong
I just started to try and learn C# after having spent some time with Python.
The thing is, when I try to debug my console application it gives 21 errors, which gives me the impression that I'm doing everything wrong. None of the errors are the "You missed a ; there" kind of errors. My question is, what am I doing wrong? I suspect it to be something that I used to do while using Python, but which is not the way to do things in C#. I do not expect you guys to read and debug all my code of course, I'm just asking for some help and general ideas about what I'm doing wrong.
My Code (it's a simple calculator):
Code:
string choice="y";
while(choice!="y" && choice!="Y")
{
Console.WriteLine("Welcome to this simple C# calculator!");
Console.Write("1st Number: ");
string input1=Console.ReadLine();
while (Int32.TryParse(input1)==false)
{
Console.Write("Please insert a number: ");
input1=Console.ReadLine();
}
int intput1=Int32.Parse(input1);
Console.Write("Operator (+, -, /, *, ^: ");
string moperator;
moperator=Console.ReadLine();
while (moperator!="+" && moperator!="-" && moperator!="/" && moperator!="*" && moperator!="^")
{
Console.WriteLine("Invalid Operator, this application only supports the following operators: +, -, /, *, ^");
Console.Write("Please specify a different operator: ");
moperator=Console.ReadKey();
}
Console.Write("2nd Number: ");
string input2=Console.ReadLine();
while (Int32.TryParse(input2)==false)
{
Console.Write("Please insert a number: ");
input2=Console.ReadLine();
}
int intput2=Int32.Parse(input2);
if (moperator=="+")
{
Console.WriteLine(input1+"+"+input2+"="+(intput1+intput2).ToString);
}
else if (moperator=="-")
{
Console.Write(input1+"-"+input2+"=");
Console.WriteLine((intput1-intput2).ToString);
}
else if (moperator=="/")
{
Console.WriteLine(input1+"/"+input2+"="+(intput1/intput2).ToString);
}
else if (moperator=="*")
{
Console.WriteLine(input1+"*"+input2+"="+(intput1*intput2).ToString);
}
else if (moperator=="^")
{
int result=1;
int repetition=0;
while (repetition<intput2)
{
result*=intput1;
repetition+=1;
}
Console.WriteLine(input1+"^"+input2+"="+(result).ToString);
}
Console.Write("Would you like to perform another calculation? (Press Y to continue, all other keys will shutdown)");
choice = Console.ReadKey();
}
Please help me?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|