Computing.Net > Forums > Programming > mobile phone menu problem c++

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

mobile phone menu problem c++

Reply to Message Icon

Name: declan
Date: November 28, 2002 at 05:14:18 Pacific
OS: win nt
CPU/Ram: 128
Comment:

hi,
im having problems coding this:
the user must input a number using getch()
and according to the number a letter must be outputted
eg
2 A
22 B
222 C
3 D
the user must enter '1' after their input to signal end of letter.
much appreciated




Sponsored Link
Ads by Google

Response Number 1
Name: HiJinx
Date: November 28, 2002 at 20:21:23 Pacific
Reply:

I played around for a few mins and came up with the following. It's simple (no error checking, etc), but it seems to be working and should give you at least an idea or two if nothing else. It assumes that 's' is the fourth letter on the 7 key and 'z' is the fourth letter on the 9. Replace the square brackets with angle ones where necessary.

#include [iostream.h]
#include [conio.h]

int main()

{

char strCode[6];
char numPad[4][9]={{"ADGJMPTW"},{"BEHKNQUX"},{"CFILORVY"},{"XXXXXSXZ"}};
char temp;
int x=0,y=0;

cout [[ "Hit 'x' to exit...\n\n\n" [[ flush;

while(1)
{

while ((temp=getch())!='1' && temp != 'x')
strCode[x++]=temp;

if (temp=='x')
break;

strCode[x--]='\0';

y=strCode[0]-50; //shift from ASCII value

cout [[ numPad[x][y] [[ flush;

x=0;

}

return 0;

}


0

Response Number 2
Name: declan murphy
Date: December 3, 2002 at 03:16:24 Pacific
Reply:

Hi,
Thanks very much for taking the time out to give me a hand. Really appreciated. But could you give me a brief run through of how it works fully....regards..declan


0

Response Number 3
Name: HiJinx
Date: December 3, 2002 at 09:41:22 Pacific
Reply:

I'm reposting the code with some comments thrown in. Hope it helps, but if it's still unclear you may want to look up double subscripted arrays and maybe have a look at an ASCII chart to get some idea of what I did what I did.


#include [iostream.h]
#include [conio.h]

int main()

{

char strCode[6]; // used to hold user input

char numPad[4][9]={{"ADGJMPTW"},{"BEHKNQUX"},{"CFILORVY"},{"XXXXXSXZ"}};
// when you line these strings up underneath each other,
// you'll notice that each column contains letters corresponding
// to a number key on the phone. ie the first column contains ABC,
// the second contains DEF, etc .
// So we have created a 'grid' of letters so that
// numPad[0][0] = 'A' numPad[0][1] = 'D'
// numPad[1][0] = 'B' numPad[1][1] = 'E'
// numPad[2][0] = 'C' numPad[2][1] = 'F'
// etc...


char temp; // receives the keypress
int x=0; //used to count number of keypresses
int y; //used to hold value of key pressed

cout [[ "Hit 'x' to exit...\n\n\n" [[ flush;

while(1)
{
// get characters until the user enters a 1 or x
// and add them into the strCode char array
while ((temp=getch())!='1' && temp != 'x')
strCode[x++]=temp;

if (temp=='x') //user decides to quit
break;

// x now contains the number of digits entered
// (not including the '1'), but since array
// starts at element 0 instead of 1, we shift
// back a step
x--;

// Look at the first character in strCode.
// Assigning it to variable 'y' gives the
// ASCII value, so we must subtract...
// 48 to get the integer value +
// 1 because lettering starts on key 2, not 1
// 1 because the array starts at 0, not 1
y=strCode[0]-50;

// we now know that the user has pressed
// the 'y' key 'x' number of times
// and can use this information to
// find the appropriate letter in the
// numPad array created earlier.
cout [[ numPad[x][y] [[ flush;

// reset counter to zero before next loop
x=0;

}

return 0;

}


0

Response Number 4
Name: declan
Date: December 5, 2002 at 05:22:15 Pacific
Reply:

once again, i really appreciate it
thanx very much...declan


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: mobile phone menu problem c++

Julius, HTK or Sphinx for mobile phone www.computing.net/answers/programming/julius-htk-or-sphinx-for-mobile-phone/20188.html

I need mobile phone tools software www.computing.net/answers/programming/i-need-mobile-phone-tools-software/12839.html

I'm having problem c++ programming www.computing.net/answers/programming/im-having-problem-c-programming/17450.html