i just want to know how can i convert a lot of char input into int. I think the one i had done is not right because it does not return integer and my current code only read first char .
Edit: Perhaps not. You want to convert characters into phone pad equivalents? The case statement you have seems fine, except you may want to add capital characters and numerics:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int getInt(char c)
{
switch(c)
{
case'1': // 1 only resolves to itself
{
return 1;
}
case'a': case'A':
case'b': case'B':
case'c': case'C':
case'2': // all these resolve to 2 on phone pad
{
return 2;
}
...
You'll also need a loop to process the input, maybe:
1 2 3 4 5 6 7
char c;
cout << "Enter phone symbol(s):";
while(cin.get(c))
{
if(c == ' ' || c == '\n') break; // stop processing on space or return
int phoneDigit = getInt(c);
}
Thank you so much i've figured out that part because of you. now trying to add another question. it'll ask whether wanna continue or not if answer is Y or y it'll continue the loop again. i also want to run another bool isValidChar to check whether the put is only A-Z,a-z and -. If the rest of the char like * or & it'll terminate translating to integer and show error message.
when the user hits enter isValidChar() will return false. All you are doing is either accepting the character or printing out an error message. You need to break; if you want to kick out of the while loop on the user pressing return.