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.
#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;
}
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!