0

I am brand new to programming. I have only learned up to functions in c++ so far, so please answer with in the scope of my knowledge.

I am working of a bank account program and I want to use a switch to get the user to input whether they want to deposit or withdraw.

I know I can use an int or even a char and do some like “D” for deposit but that’s not what I want to do.

I want to able to use the whole string “deposit” with the switch statement.

Thank you!

  • 1
    Short answer: You can't, only integer numeric values are allowed to use with a `switch` (note: a single `char` also is a numeric value). Use an `if() {} else if() {} else {}` cascade instead. – πάντα ῥεῖ Oct 03 '20 at 19:31

1 Answers1

1

The switch statement in c++ only supports integer types or values that can be evaluated to an integer. At best you could write a function to evaluate your strings to an integer as mentioned here
ref: Evaluate a string with a switch in C++

Ameya Rane
  • 286
  • 1
  • 7