本文介绍了用sin,cos& amp;的方法问题棕褐色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai,我的代码有问题,目前,我正在创建具有sin,cos& cos函数的科学计算器.棕褐色.我创建的代码无法正常工作,因为每次转换函数时,它将显示0作为答案.请在这里为我提供纠正方法的建议.

Hai, i have probleam with my code, currently i am create scientific calculator which have function sin, cos & tan. The code i create it not working because every time i convert the function it will show 0 as answer.Please advice me how to correct my code here.

Public Class Form1
    Dim total1, total2 As Double
    Dim [Operator] As String
    Const conversionFactor As Double = Math.PI / 180
Dim result As Double
        total2 = Val(answer.Text)

        Select Case [Operator]
             Case "SIN"
                result = Math.Sin(total1 / conversionFactor)
                answer.Text = result
            Case "COS"
                result = Math.Cos(total1 / conversionFactor)
                answer.Text = result
            Case "Tan"
                result = Math.Tan(total1 / conversionFactor)
        End Select
        answer.Text = result
    End Sub 

推荐答案


total2 = Val(answer.Text)



这样一来,您就可以检查该方法执行过程中发生了什么.

这可能很有趣:在Visual Studio中调试 [ ^ ]

最好的问候
Espen Harlinn



That will allow you to inspect what''s going on as the method executes.

This might be interesting: Debugging in Visual Studio[^]

Best regards
Espen Harlinn


enum Operator { sin, cos, tag, /*...*/}



制作一个字典,根据每个运算符的值查找委托实例:



Make a dictionary which finds a delegate instance by each operator''s value:

using OperatorDictionary = System.Collections.Generic.Dictionary<Operator, OperatorApplication>;

//...

delegate double OperatorApplication(double left, double right);



如果您使用表达式解析文本,则同样的想法也适用.将其解析为某种逻辑结构,其中操作员代码是上面显示的枚举,而不是字符串.这样的事情.使用您的字符串类型的立即常量,甚至使用显式的字符串常量,您很快就会陷入支持问题.不要锁住自己.

—SA



The same idea works if you parse text with expression. Parse it into some logical structure, where the operator code is enumeration shown above, not string. Something like that. With your immediate constants of the string type, even with explicit string constants, you will get sunk in support issues pretty soon. Don''t lock yourself.

—SA


这篇关于用sin,cos&amp; amp;的方法问题棕褐色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:19
查看更多