- Joined
- Sep 22, 2012
- Messages
- 90
hello peepz,
I have a problem with a C++ problem: "build a program that would print the letters on a cellphone keypad (oldschool 3x4 nokia3310 stuff) and vice versa".
So far I've only made the numkeys to charkeys: 2 = "abc".
>I'm trying to apply the trick they call "fake arrays" but the thing is when it comes to key 7 and 9 the chracters there are 4: 7 = "pqrs".I've solved this and I'm certain that my option numtochar>>keys are working, but how should do it the other way around?
Here's my code:
I do hope someone could help but not too overboard. I know I'm going far off the site's regulation but i ran out of options since other forums are taking too long to respond.
I have a problem with a C++ problem: "build a program that would print the letters on a cellphone keypad (oldschool 3x4 nokia3310 stuff) and vice versa".
So far I've only made the numkeys to charkeys: 2 = "abc".
>I'm trying to apply the trick they call "fake arrays" but the thing is when it comes to key 7 and 9 the chracters there are 4: 7 = "pqrs".I've solved this and I'm certain that my option numtochar>>keys are working, but how should do it the other way around?
Here's my code:
JASS:
#include <iostream>
using namespace std;
int numkey;
char operation,charkey;
char key_elem[]="abcdefghijklmnopqrstuvwxyz";
//to_keys 22233344455566677778889999* --27+nullchar|0to25
//to_nums_placer 0 1 2 3 4 5 6 7-*
//to_nums_set -3--3--3--3--3---4--3---4-*
/******************************
*cellkeys
*valid only to those phones with a 3x4 key layout
******************************/
int main()
{
cout<<"---number keys---\n";
cout<<"Supports only lower case characters and numbers from cellphone keys\n";
while (operation !='x')
{
cout<<"\n\n\n\n\n\n----------------------\n";
cout<<"1> numkeys to chars\n";
cout<<"2> charkeys to numkeys\n";
cout<<"x> to EXIT\n";
cout<<"----------------------\n";
cout<<"enter operation:";
cin>>operation;
switch (operation){
//case1
case '1':
{
cout << "enter numkey:";
cin >> numkey;
if (numkey>1&&numkey<10){
numkey=numkey-2;
int iter=0,placer=3,ender=3;
iter=numkey*placer;
//getexactinit
if (numkey==5)//incase7
{ender=4;}
else if (numkey==7)//incase9
{iter=iter+1;ender=ender+1;}
else if(numkey==6){iter=iter+1;}//incase8
//--------------------------------
//cout<<"placer: "<<placer<<endl;
//cout<<"ender: "<<ender<<endl;
//cout<<"iter: "<<iter<<endl;
//--------------------------------
//getexactend
ender=iter+ender;
//printelementsfromto
for(;iter<ender;cout<<"element: "<<key_elem[iter]<<"\n",iter++)
{}
}
else{
cout<<"no chars defined for that numkey"<<endl;}
break;
}
//endcase1
//case2-notworking:(((-
case '2':
{
cout << "enter your charkey:";
cin >>charkey;
int x=0,y=0,z=0,k=0,sub_size=3,temp_key;
//findthatkey
for(;x<26;x++)
{
if(charkey==key_elem[x]){break;}
}
//skipcounttogetcellkey
for(; y<8 ;y++)
{
//getsubkeys
for( z=(z*3); ; ){}
}
}
//endcase2
//default
default:
{
if (operation=='x'){cout<<"exiting....\n";}
else {cout<<"\n****invalid operation!!\n";}
}
}
}
system("PAUSE");
return 0;
}
I do hope someone could help but not too overboard. I know I'm going far off the site's regulation but i ran out of options since other forums are taking too long to respond.
Last edited by a moderator: