C++ Character Press Count

Hi everyone :D,

I am making a console app in Dev C++. I was wondering if it is possible for the application to register the number of times a character is entered and change the result accordingly, for example:

if "a" is pressed, then print "4"

if "b" is pressed, then print "3"

if "a" is pressed for the 2nd time, then print "z"

if "b" is pressed for the 2nd time, then print "h"

if "a" is pressed for the 3rd time, then print "4" again

thanks

Muhasaresa :)
have three input variables.
then 3 if statements for each input variable.
post again if you need more help.
Thanks, but unfortunately, due to my code so far I am unable to do this (sorry I did not mention it in my first post; my mistake).

Is there a function that either:

- registers the nth input of one character. If n is even, print "z" if odd print "4".

or

- if "a" is input, then add Either "4" to the string OR "z"

I tried
1
2
3
4
5
ch=char(getch()); 
     
     if(int(ch) == 97){ 
                cout<<"a"; 
                encr += "128." || "43.";}


but that did not seem to work.

Thanks,

Muhasaresa
closed account (DSLq5Di1)
1
2
int char_count[26] = {};
char ch;

1
2
3
4
5
6
7
8
9
10
11
cin.get(ch);

if (ch == 'a')
{
    int is_odd = ++char_count[ch - 'a'] % 2;

    if (is_odd)
    {
        ...
    }
}
Topic archived. No new replies allowed.