using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class CalculateNumber
{
int Number1, Number2;
char option;
int Result;
public void Number()
{
Console.WriteLine("Enter the First number");
Number1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the second number");
Number2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Main Menu");
Console.WriteLine("1.Addition");
Console.WriteLine("2.Subtraction");
Console.WriteLine("3.Multiplication");
Console.WriteLine("4.Division");
Console.WriteLine("Enter the Operation you want to perform");
option = Convert.ToChar(Console.ReadLine());
while(1)
{
switch (option)
{
case '1':
Result = Number1 + Number2;
Console.WriteLine("The result of addition is:{0}", Result);
break;
case '2':
Result = Number1 - Number2;
Console.WriteLine("The result of Subtraction is:{0}", Result);
break;
case '3':
Result = Number1 * Number2;
Console.WriteLine("The result of Multiplication is:{0}", Result);
break;
case '4':
Result = Number1 / Number2;
Console.WriteLine("The result of Division is:{0}", Result);
break;
default:
Console.WriteLine("Invalid Option ");
break;
}
}
}
Console.ReadLine();
}
}
class ClassMain
{
static void Main(string[] args)
{
CalculateNumber obj = new CalculateNumber();
obj.Number();
}
}
}
// i want this calculator to rerun but once i select a case the program goes unhandable
amitchawla
0
Newbie Poster
Recommended Answers
Jump to PostThat is because you used a constant number as your loop controller. iin the line where you said
while(1)
so the loop will continue going on because 1 will always equal to itself.
If that's how you want it (case inside loop), then use code like:
Jump to Postwhile(1)
This will never work, C# expects a boolean or an expression that resolves to a boolean. The number 1 resolves to an integer. This is one of the reasons I prefer C# over C and C++ !
All 5 Replies
mshauny
25
Junior Poster in Training
ddanbe
2,724
Professional Procrastinator
Featured Poster
reemhatim
-5
Light Poster
reemhatim
-5
Light Poster
rohand
1
Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.