Codes

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;
//........... 
That'd be easy:
1
2
cout << "Code Please";
cin >> footmen >> archers >> knights >> ghosts >> zombies >> skeletons;
I wouldn't recommend that though
thanks mate and why wouldn't yourecommend it?
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';
  ...
}
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
Sure, a string can contain everything. you just need to identify it
Thanks im still a bit new don't really know how to use strings
you can use a string like an array. The function size() (as shown above) tells how many char the string contains. See:

http://www.cplusplus.com/reference/string/string/?kw=string

just try
Topic archived. No new replies allowed.