0
Need a little help
Hi everyone! I’m relatively new to programming and I’ve recently started c++. I have a WIP program here for a very (very) simple calculator. I’m trying to build it using no reference so sorry if it’s a little jumbled and dragged out. My problem is that whenever I try to do subtraction it just defaults to addition and I can’t figure out why. Also, it always prints a weird number after the outputted answer and idk what it is. Help would be appreciated :) https://code.sololearn.com/coyAOrw5Wk7J/?ref=app
5 Réponses
+ 1
https://code.sololearn.com/csZ99t1bgW0C/?ref=app
+ 3
If you want to chain conditions, you have to do it explicitely, e.g.
if ( CalkChoice == "Add" || CalkChoice == "add" || ... )
Currently, the compiler implicitely converts the other strings after the first comparison to boolean values, and since the strings are not null, the whole condition becomes true, regardless of what has been entered.
Also, on a sidenote, I would recommend getting the input inside the main() function, because this way you have a lot of duplicate but redundant code and at least two unused variables.
+ 2
U made your code complex
Use small variables name and use switch case u can make it easy
+ 1
Hello Wesley ,
there are lot of bugs in your code, I'll send your code to you shortly after debugging it.
+ 1
Wesley check it out