How to take different types of input in c++ -
in program i'm working on, scan 1 character input, (w,a,s,d)
cin >> input; but want make if user enters 'p', example, further allow him enter 2 more values.
for example, entering 'a' move left. entering 'p 3 100' place number 100 in array position 3.
id prefer dont have press enter after inputting p, because means add condition statement if (input==p)
i recommend keep simple:
just keep checking 1 character and, if given character p ask other arguments user.
for instance:
edit code edited match op requirements.
char option; cout << "enter option: "; cin >> option; switch (option) { case 'a': // things. break; case 'p': int number, position; cin >> number; cin >> position; // things. break; // don't forget default case. }
Comments
Post a Comment