Click here to Skip to main content
15,902,938 members
Home / Discussions / C#
   

C#

 
GeneralRe: sharing an event handler, not getting what I expect Pin
Luc Pattyn1-Oct-07 5:49
sitebuilderLuc Pattyn1-Oct-07 5:49 
GeneralRe: sharing an event handler, not getting what I expect Pin
TJoe1-Oct-07 5:56
TJoe1-Oct-07 5:56 
GeneralRe: sharing an event handler, not getting what I expect Pin
JoeRip1-Oct-07 5:57
JoeRip1-Oct-07 5:57 
GeneralRe: sharing an event handler, not getting what I expect [modified] Pin
Luc Pattyn1-Oct-07 6:03
sitebuilderLuc Pattyn1-Oct-07 6:03 
GeneralRe: sharing an event handler, not getting what I expect Pin
TJoe1-Oct-07 4:50
TJoe1-Oct-07 4:50 
QuestionProblem with macros Pin
yadlaprasad1-Oct-07 3:29
yadlaprasad1-Oct-07 3:29 
AnswerRe: Problem with macros Pin
TJoe1-Oct-07 3:48
TJoe1-Oct-07 3:48 
Questionhelp with code to implement a calculator.... Pin
MinhajuddinK1-Oct-07 3:25
MinhajuddinK1-Oct-07 3:25 
Hi all,

I am new to C#....

I thought that implementing a simple calculator would help me understand the language... I have come up with a code....

It would be great if the gurus here give me feedback on this...

<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
<br />
namespace Calculator<br />
{<br />
    class compute<br />
    {<br />
        private string[] inputNumbers;<br />
        public string computeResult(string inputExpression)<br />
        {<br />
            string result = "There was an error while processing!";<br />
            inputExpression = inputExpression.Replace("+", "+A");<br />
            inputExpression = inputExpression.Replace("-", "-S");<br />
            inputExpression = inputExpression.Replace("*", "-M");<br />
            inputExpression = inputExpression.Replace("/", "/D");<br />
<br />
            if (inputExpression.Substring(0, 1) != "-" && inputExpression.Substring(0, 1) != "+")<br />
                inputExpression = "A" + inputExpression;<br />
            else<br />
                inputExpression = inputExpression.Substring(1);<br />
            inputNumbers = inputExpression.Split('+', '-', '*', '/');<br />
<br />
            decimal output=0;<br />
            int i;<br />
            int count = inputNumbers.Length;<br />
            for (i = 0; i < count; i++)<br />
            {<br />
                string calc = "";<br />
                inputNumbers[i] = inputNumbers[i].Trim();<br />
                decimal temp;<br />
                if (!decimal.TryParse(inputNumbers[i].Substring(1),out temp))<br />
                    break;<br />
                calc = inputNumbers[i].Substring(0,1);<br />
<br />
                switch(calc)<br />
                {<br />
                    case "A":<br />
                        output = output + temp;<br />
                        break;<br />
                    case "S":<br />
                        output = output - temp;<br />
                        break;<br />
                    case "M":<br />
                        output = output * temp;<br />
                        break;<br />
                    case "D":<br />
                        output = output / temp;<br />
                        break;<br />
                }<br />
<br />
                <br />
            }<br />
            <br />
            if(i==count)<br />
                result = output.ToString();<br />
            return result;<br />
        }<br />
    }<br />
}<br />
<br />



You don't have to be AFRAID!

AnswerRe: help with code to implement a calculator.... Pin
led mike1-Oct-07 4:43
led mike1-Oct-07 4:43 
AnswerRe: help with code to implement a calculator.... Pin
Luc Pattyn1-Oct-07 4:55
sitebuilderLuc Pattyn1-Oct-07 4:55 
GeneralRe: help with code to implement a calculator.... Pin
MinhajuddinK1-Oct-07 7:32
MinhajuddinK1-Oct-07 7:32 
QuestionAmbiguous Date Format in Excel Pin
meeram3951-Oct-07 3:21
meeram3951-Oct-07 3:21 
AnswerRe: Ambiguous Date Format in Excel Pin
raja mohamed21-Jul-09 2:15
raja mohamed21-Jul-09 2:15 
QuestionSystem.IO.Compression Pin
Vodstok1-Oct-07 3:12
Vodstok1-Oct-07 3:12 
AnswerRe: System.IO.Compression Pin
TJoe1-Oct-07 3:16
TJoe1-Oct-07 3:16 
GeneralRe: System.IO.Compression Pin
Vodstok1-Oct-07 3:22
Vodstok1-Oct-07 3:22 
GeneralRe: System.IO.Compression Pin
TJoe1-Oct-07 3:25
TJoe1-Oct-07 3:25 
GeneralRe: System.IO.Compression Pin
Vodstok1-Oct-07 3:33
Vodstok1-Oct-07 3:33 
AnswerRe: System.IO.Compression Pin
Scott Dorman1-Oct-07 3:25
professionalScott Dorman1-Oct-07 3:25 
AnswerRe: System.IO.Compression Pin
Luc Pattyn1-Oct-07 5:03
sitebuilderLuc Pattyn1-Oct-07 5:03 
GeneralRe: System.IO.Compression Pin
Vodstok1-Oct-07 5:08
Vodstok1-Oct-07 5:08 
GeneralRe: System.IO.Compression Pin
Luc Pattyn1-Oct-07 5:59
sitebuilderLuc Pattyn1-Oct-07 5:59 
GeneralRe: System.IO.Compression Pin
Vodstok1-Oct-07 6:21
Vodstok1-Oct-07 6:21 
Questionindex server Pin
Sunil Wise1-Oct-07 3:09
professionalSunil Wise1-Oct-07 3:09 
AnswerRe: index server Pin
Andrei Ungureanu1-Oct-07 4:57
Andrei Ungureanu1-Oct-07 4:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.