Codes
Nov 25, 2013 at 12:40pm UTC
I need to get an input which takes a bunch of numbers you insert so like 294745
makes 2 footmen 9 archers 4 knights 7 ghosts 4 zombies 5 skeletons
is there any way to do this in one line of input
1 2 3 4 5 6 7 8 9 10 11
//.....
int footmen;
int archers;
int knights;
int ghosts;
int zombies;
int skeletons;
int code;
cout << "Code Please" ;
cin >> code;
//...........
Nov 25, 2013 at 12:49pm UTC
That'd be easy:
1 2
cout << "Code Please" ;
cin >> footmen >> archers >> knights >> ghosts >> zombies >> skeletons;
I wouldn't recommend that though
Nov 25, 2013 at 12:51pm UTC
thanks mate and why wouldn't yourecommend it?
Nov 25, 2013 at 1:06pm UTC
I forgot to say that you need to enter space in order to separate the numbers.
why wouldn't yourecommend it?
It's way to obscure.
if you want it that obscure and no space you could to this (it does not allow numbers > 9):
1 2 3 4 5 6 7 8 9 10 11
...
string code;
cout << "Code Please" ;
getline(cin, code);
if (code.size() >= ...)
{
footmen = code[0] - '0' ;
archers = code[1] - '0' ;
knights = code[2] - '0' ;
...
}
Nov 25, 2013 at 1:09pm UTC
And if i would want to use letters in the code to times the numbers like b2 would be 4 (b=2 x 2) or k9 = 99
is there a way to do that
Nov 25, 2013 at 8:52pm UTC
Sure, a string can contain everything. you just need to identify it
Nov 26, 2013 at 7:23am UTC
Thanks im still a bit new don't really know how to use strings
Nov 26, 2013 at 12:49pm UTC
Topic archived. No new replies allowed.