Questions about char vector

OK. Here is my problem. One of the exercises in my book wants me to write a program. It basically boils down to this. It wants me to take a input of a number of up to 4 digits as chars such as 5432. It then wants me to take the chars and recreate the number(ie. print 5432 again as a single int).Below is the code I wrote, but I keep having the same problem I left the newest code where I tried a different approach with the same error. It tells me "Term does not evaluate to a function taking one argument" I am not understanding why I get the same error with both approaches.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "..\..\std_lib_facilities.h"

int chars(char x)
{
	switch (x)
	{
	case '0':
		return 0;
		break;
	case '1':
		return 1;
		break;
	case '2':
		return 2;
		break;
	case '3':
		return 3;
		break;
	case '4':
		return 4;
		break;
	case '5':
		return 5;
		break;
	case '6':
		return 6;
		break;
	case '7':
		return 7;
		break;
	case '8':
		return 8;
		break;
	case '9':
		return 9;
		break;
	}
}

int main()
{
	try {
		cout << "Please enter a number, up to 4 digits:\n";
		vector <char> z(4);
		char digit;
		while (cin >> digit)
			z.push_back(digit);
/* This is where I keep getting errors. The first was a modified attempt that gave me the same error.The other three lines are the format I origionally used when I started getting the errors. */
		int a = int(z{ 0 }) *1000;
		int b = chars(z{1}) * 100;
		int c = chars(z{2}) * 10;
		int d = chars(z{3});
		int sum = a + b + c + d;
		cout << "\nYou entered " << sum;
	}
You accidentally used curly braces instead of square brackets to index into the vector.
Thank You! I have skimmed over this code like 20 times. I am a blind user and did not listen close enough to see one was a bracket and the other was a brace. Thank you, thank you thank you!
Topic archived. No new replies allowed.