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

28th Mar 2020, 9:00 PM
Wesley
5 Respostas
+ 1
https://code.sololearn.com/csZ99t1bgW0C/?ref=app
28th Mar 2020, 9:35 PM
Muhammad Faheem Nasir
Muhammad Faheem Nasir - avatar
+ 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.
28th Mar 2020, 9:12 PM
Shadow
Shadow - avatar
+ 2
U made your code complex Use small variables name and use switch case u can make it easy
30th Mar 2020, 7:20 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Hello Wesley , there are lot of bugs in your code, I'll send your code to you shortly after debugging it.
28th Mar 2020, 9:10 PM
Muhammad Faheem Nasir
Muhammad Faheem Nasir - avatar
+ 1
Wesley check it out
28th Mar 2020, 9:36 PM
Muhammad Faheem Nasir
Muhammad Faheem Nasir - avatar