This was asked in a interview by Cognizant Technologies

Print the name in center of the screen and then make the letter drop one by one out of the screen how to solve this ?

ex.

Every thing must be in the center of the screen

Daniel

then 'l' must fall down out of the screen then r then i and so on ... Please Help

Recommended Answers

All 3 Replies

Does it have to be in C++? Can you use external libraries?

no external libraries. just with normal C++..

I assume you mean the console screen.

First you have to figure out the screen width in characters. The old MS-DOS window was 80 characters wide, but that is no longer true. Once you know the screen width then the rest should be easy math. Something like this:

int main()
{
    std::string name = "Daniel";
    const int ScreenWidth = 80;
    while( name.length() > 0)
    {
        int center = (ScreenWidth-name.length())/2;
        cout << setw(center) << " " << name << '\n';
        name = name.substr(1);
    }
}
commented: MS dos is not the command shell anyway.`cmd.exe` is a command interpreter and it's completely 32-bit mode command shell ,in 64 bit environments the older protected mode environment was not exists anymore. and command.com is different from cmd.exe. +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.