简易计算器

时间:2019-03-07 11:34:07

标签: c++ calculator

伙计们,我是C ++自学的初学者。 今天,我尝试制作一个简单的计算器,但调试器不断地向我展示相同的错误。一元化变量使用“ X”;一元化变量使用“ Z”

这是代码:

hp.loguniform(label, low, high)

2 个答案:

答案 0 :(得分:0)

在读取ax之后,应该初始化变量并计算z。看一下这个:https://www.learncpp.com/cpp-programming/eight-c-programming-mistakes-the-compiler-wont-catch/

#include <iostream>
using namespace std;

int main()
{
    float x = 0.0f, z = 0.0f, a = 0.0f;

    cout << "Welcome to the calculator" << endl;
    cout << "State the first number " << endl;
    cin >> x ;
    cout << "State the second number " << endl;
    cin >>  z ;
    a = x + z;
    cout << "If you wanted to time number" << x << "by this number" << z << "The result would be : " << a << endl;



    system("pause");
    return 0;
} 

答案 1 :(得分:0)

您做事的顺序很重要。

int scoreBase = (int) dataSnapshot.getValue(Integer.class);

因此,在您的代码中,int x = 5, z = 2; int a = x + z; // a is 7 z = 5; // a is still 7 a = x + z; // now a is updated to 10 a = x + z;都未初始化。使用未初始化的变量是不确定的行为。

要解决此问题,请在向xz输入值之后将a = x + z;移至。