Help, plz. Wrote a primitive calculator that accepts user expressions: +, -, /, * ,. So, despite the entered numbers, it gives the same answers for expressions with the same mate. operations. So for example 2 + 2, 4 + 8 and so on. will be equal. The same is true for other mate. operations. The program is written in two CPP files + one header file. Code link here

Shl: about the provision of the code, I tried to put it in the text, but only a lot of hemorrhoids: Sharp makes the text bold-large, the content in angle brackets is not displayed, and so on.

  • 3
    I suggest you tear out the part of the code that is specifically responsible for mathematics and put it here. - VioLet
  • The code in the studio! - sudo97

1 answer 1

Your mistake is here:

double x, y; char sig; // ... scanf("%f%c%f", &x, &sig, &y); 

scanf c "% f" will write a value of type float, and you have two variables of type double. Your scanf needs to be replaced by

 std::cin >> x >> sig >> y; 

or at

 scanf("%lf%c%lf", &x, &sig, &y); 
  • Thanks to the Comrade gkuznets. Indeed the problem was solved. But another question: I type exit to exit - it includes an endless loop. - Warbit
  • As far as I remember, the value of the variable input is compared in your cycle with the "exit", while the input variable itself is never updated. - gkuznets
  • That's right - Warbit