-3

I am relatively new to programming, and I can only really understand C++. I have recently started working on a project that requires the user to input something that will allow them to make a selection. I can't figure out how to make it possible for the user to input a string or a char but get the same result. I know that this would require that I assign the variable that the user inputs (for example 'a') two data types, but how do I do that? I've tried using "string/char a;" but that doesn't work.

Could someone please help me with multi-data-type variables?

Thanks

user2602989
  • 1
  • 1
  • 2

2 Answers2

1

The string type will work for all user input. Since it "doesn't work" for you, we can't help you further if you don't show us what you tried.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • Here is a compressed example version of it: – user2602989 Jul 20 '13 at 23:57
  • I basically just wrote "string a" and had the user input the answer to a question. I used an if statement to determine what to do with their answer, and the multiple choice answers went like this: "A. (example), B. (example)" when the user inputs the answer, I wanted them to have the option of writing "A" or "(example)". But it kept giving me errors because I used the string data type for "a". Sorry I couldn't give you the actual code because this is a comment. – user2602989 Jul 21 '13 at 00:05
1

If the User is the one making the Input from the I/O, then you get to decide if you will treat the input as a string or char. After receiving the Input you should know what you want to do with it. And you can also store the input data in array, vectors or list. Primitive data types can do so many things just understand the purpose and function of your program.

Juniar
  • 1,269
  • 1
  • 15
  • 24