CrazyEngineers
  • 10th C++ problem

    Manish Goyal

    Member

    Updated: Oct 26, 2024
    Views: 1.1K
    write a program similar to mobile key system?
    Like say you want to send a message to someone
    then if you press 2 one times then press enter it will display a,if 2 times then enter it will display b,if three then c
    similarly upto key 9 you have to make this program

    One constraint:Say if i press 2 then press 3 without pressing enter it should display error 😉

    Note:There is no need of graphic interface :just print output on console
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • gaurav.bhorkar

    MemberMar 7, 2010

    That's an interesting program. I'll try that after I finish my college today.
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberMar 8, 2010

    I am waiting Gaurav.
    This program was asked in a coding competition that i had participated last month
    Are you sure? This action cannot be undone.
    Cancel
  • silverscorpion

    MemberMar 8, 2010

    I think this can be easily done by a simple switch case since only one character is to be deduced from the input at a time. The code goes something like this:

    char ans; int a;
    scanf("%d",&a);
    switch (a)
    {
    case 2: ans='a'; break; case 22: ans='b'; break; case 222: ans='c'; break;
    case 3: ans='d'; break; case 33: ans='e'; break; case 333: ans='f'; break;
    case 4: ans='g'; break; case 44: ans='h'; break; case 444: ans='i'; break;
    case 5: ans='j'; break; case 55: ans='k'; break; case 555: ans='l'; break;
    case 6: ans='m'; break; case 66: ans='n'; break; case 666: ans='o'; break;
    case 7: ans='p'; break; case 77: ans='q'; break; case 777: ans='r'; break; case 7777: ans]='s'; break;
    case 8: ans='t'; break; case 88: ans='u'; break; case 888: ans='v'; break;
    case 9: ans='w'; break; case 99: ans='x'; break; case 999: ans='y'; break; case 9999: ans='z'; break;
    default: printf("Error. Invalid sequence.");
    }
    You can also keep a flag variable and depending on whether it is one or zero, you can assign either capital letters or small letters too.. this will do it. What do you say??
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberMar 8, 2010

    Quite nice attempt scorpion

    but i want that if someone press 2 then if without pressing enter he presses 3 or

    something else immediately it will display error without waiting for you to press enter
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberMar 9, 2010

    I was thinking quite similar to silverscorpion. The break statement after each case is missing in his program. Also print the character after the switch ends.
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberMar 9, 2010

    come on guys keep thinking
    frankly saying i was also not able to make this program during that competition but after that i tried this at home and i made it
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberMar 10, 2010

    So here is the code for this..if anyone can make it more simpler then he is welcome
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    char ch;
    char one[]={'a','b','c'};
    char two[]={'d','e','f'};
    char three[]={'g','h','i'};
    char four[]={'j','k','l'};
    char five[]={'m','n','o'};
    char six[]={'p','q','r','s'};
    char seven[]={'t','u','v'};
    char eight[]={'w','x','y','z'};
    ch=getch();
    int c=ch;
    int count=-1,store[1];
    while(c!=13)
    {
    
        if(count==-1)
            {
                store[0]=c;
            }
            if(c!=store[0]&&c!=13)
            {
                cout<<"Error"<<endl;
                exit(0);
            }
            else
            {
                count++;
            }ch=getch();
    c=ch;
    
    }
    if(store[0]==50)
    {
    cout<<one[count];
    }
    if(store[0]==51)
    {
    cout<<two[count];
    }if(store[0]==52)
    {
    cout<<three[count];
    }if(store[0]==53)
    {
    cout<<four[count];
    }if(store[0]==54)
    {
    cout<<five[count];
    }if(store[0]==55)
    {
    cout<<six[count];
    }if(store[0]==56)
    {
    cout<<seven[count];
    }if(store[0]==57)
    {
    cout<<eight[count];
    }
    
    }
    
    Are you sure? This action cannot be undone.
    Cancel
  • manav1

    MemberMar 10, 2010

    hi!! Goyal ,That's an interesting program
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberMar 10, 2010

    hi manav
    First of all welcome to ce
    second just be active on ce you will find more interesting things here
    Are you sure? This action cannot be undone.
    Cancel
  • HImanshu_Sharma

    MemberMar 13, 2010

    Yeah Gaurav you are right,,,i hv found many interesting things here...
    my question can u make a folder whch dont hav name??????
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberMar 14, 2010

    @ Himanshu .Yes we can but this is not the right place to ask your question.
    just create a new thread in appropriate section

    anyway .. create a new folder and click on rename and press alt+0160

    You will get a folder with no name
    Are you sure? This action cannot be undone.
    Cancel
  • imlitoshi11

    MemberMar 14, 2010

    goyal i like ur code.....hats off
    Are you sure? This action cannot be undone.
    Cancel
  • HImanshu_Sharma

    MemberMar 14, 2010

    ok i'l remember actually m new na so,,,bt i hv another solution for it...
    Are you sure? This action cannot be undone.
    Cancel
  • HImanshu_Sharma

    MemberMar 14, 2010

    dear its nt working,,,space bar shud be also pressed wid alt and this code...get it
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberMar 14, 2010

    @imlitoshi thanks for appreciation

    @ himanshu okk Sir and please avoid sms text .
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register