Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C++
#include <stdio.h>
void main()
{
    char znak = ' ';
    long brojac = 0;
	
    while( znak != '\e' )
    {
        switch( znak = getch() )
	{
	    case 'a' :
	    case 'e' :
	    case 'i' :
	    case 'o' :
	    case 'u' :
	        brojac++ ;
		break;
            default  :
	        brojac--;
        };
	printf( "%i", brojac );			
    };
}


What I have tried:

Can someone explain what will be printed on a screen If I type word grejanje, and what \e command means?
Posted
Updated 29-Nov-19 22:45pm
v3
Comments
phil.o 29-Nov-19 15:32pm    
I am not sure \e corresponds to anything; I don't know it, and a quick search did not bring anything.
Are you sure it's not a typo? Otherwise, you should ask the original writer what was his intention when he wrote that.
Levin101q 29-Nov-19 15:45pm    
Actually \e means that the program will stop with looking at the letters at the moment when you press the enter.

Almost certainly '\e' should be '\0xe' which is a hexadecimal value corresponding to CTRL+N, the character that is often generated when you press the ENTER key - it's more often entered as '\n' instead though.

As to what is generated, if you type a vowel the number goes up, a consonant will reduce it. It starts at 0, so it's simple for you to work out.

But seriously: this is the second "what will this do?" question from you today - both of them homework, I suspect - and you should be working it out for yourself. Try running the code you were given to see what it would do, then use the debugger to find out why. You will learn things that way, which you don't learn by getting given the answers ... and it's actually quicker than waiting for other to do your homework for you!
 
Share this answer
 
Quote:
what \e command means?

Looks like \e is a non standard escape sequence for the Escape key.
Rules for C++ string literals escape character - Stack Overflow[^]
Quote:
Can someone explain what will be printed on a screen if I type word grejanje

First, you can experiment and run the code with different inputs.
As I already told in your previous question, the debugger will show you what the code is doing, step by step. Give it a try.
Can someone explain me how did I get 5135311?[^]
-----
Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
C++
#include <stdio.h>
void main()
{
    char znak = ' ';
    long brojac = 0;

    while( znak != '\e' )
    {
        switch( znak = getch() )
        {
        case 'a' :
        case 'e' :
        case 'i' :
        case 'o' :
        case 'u' :
            brojac++ ;
            break;
        default  :
            brojac--;
        };
        printf( "%i", brojac );
    };
}

Indentation style - Wikipedia[^]

Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900