calculator

4. Implement simple calculator program in C# to perform the following

Page 1 of 1

2 Replies - 2269 Views - Last Post: 26 January 2010 - 04:22 AM Rate Topic: -----

#1 nilan59   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-January 10

calculator

Posted 26 January 2010 - 03:25 AM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace assmnt_3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your first number");
            double a = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Enter your calculation mark represent number as follows\nAddition=1\nSubstraction=2\nMultiplication=3\nDivision=4");
            bool c =Convert.ToBooleanConsole.ReadLine();
            Console.WriteLine("Enter your second number");
            double b = Convert.ToDouble(Console.ReadLine());
            Double answ;
           if (c==1)
               answ=a+b;
           else if (c==2)
              answ= a-b;
           else if (c==3)
               answ=a*b;
           else if (c==4)
               answ=a/b;
           else Console.WriteLine("Not a valied maltiplication Number");
            Console.WriteLine("Your answer is "+answ);
            Console.ReadLine();

           
            Console.WriteLine("Your answer is "+c);
            Console.ReadLine();
                

        }
    }
}


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 26 January 2010 - 06:59 AM


Is This A Good Question/Topic? 0
  • +

Replies To: calculator

#2 janne_panne   User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: calculator

Posted 26 January 2010 - 03:57 AM

You can't compare boolean and integer values like you are doing with the (c == 2). Try to use int c instead of bool c.

int c = Convert.ToInt32(Console.ReadLine());


Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: calculator

Posted 26 January 2010 - 04:22 AM

Please learn to use the code tags
:code:

Also, please state your problem in the body of the post along with any error messages you are getting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1