using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Assignment2
{
class Program
{
static void Main(string[] args)
{
int Value1,Value2,result,a;
Console.Write("Enter Value 1: ");
Value1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Value 2: ");
Value2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Choose an arithmetic operator:");
Console.WriteLine("\t1. +(add)");
Console.WriteLine("\t2. -(subtract)");
Console.WriteLine("\t3. *(multiply)");
Console.WriteLine("\t4. /(divide)");
Console.Write("\t5. %(mod)");
Console.Write("\n\n");
a = Convert.ToInt32(Console.ReadLine());
switch (a)
{
case"1":
Console.WriteLine("Operator is: Add");
result=Value1+Value2;
Console.WriteLine("Result: "+result);
break;
case"2":
Console.WriteLine("Operator is: Subtract");
result=Value1-Value2;
Console.WriteLine("Result: "+result);
break;
case"3":
Console.WriteLine("Operator is: Multiply");
result=Value1*Value2;
Console.WriteLine("Result: "+result);
break;
case"4":
Console.WriteLine("Operator is: devide");
result=Value1/Value2;
Console.WriteLine("Result: "+result);
break;
case"5":
Console.WriteLine("Operator is: mod");
result = Value1 % Value2;
Console.WriteLine("Result: "+result);
break;
}
}
}
}
i have basic C# and i try to make a program that can run 5 arithmetic operation using Case Statement, after i complete my coding..i found 5 error that make me stuck..and the output will always come with 2 result(i.e i choose Add..and 2 output will appear,its add and subtract at same time..can someone help me with this?
The offending code are your case statements.
ais anint. Your case statements all usestrings. Simply remove the quotes around the numbers: