Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
3
Answers
I need help with my simple calculator!
Orange North
7y
396
1
Reply
I just started learning C# and i wanted to build a simple calculator but I keep getting error messages
The error message I keep getting is :
Error CS0165 Use of unassigned local variable 'result'
class
Program
{
static
void
Main(
string
[] args)
{
int
num01 = Convert.ToInt32(Console.Read());
char
method = Console.ReadKey().KeyChar;
int
num02 = Convert.ToInt32(Console.Read());
int
result;
switch
(method)
{
case
'+'
:
result = num01 + num02;
break
;
case
'-'
:
result = num01 - num02;
break
;
case
'%'
:
result = num01 % num02;
break
;
case
'*'
:
result = num01 * num02;
break
;
default
:
Console.WriteLine(
"???"
);
break
;
}
Console.WriteLine(
"The answer is "
, result);
Console.ReadKey();
}
}
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
What is await Task.Delay(500) And why use
how to genarate Random string in C#