Simple C++ tricks to show up

Do you guys know any simple C++ trick that can be coded in 10 minutes? My friend asked me to show him "The Magic of Programming", I mean some cool tricks. I want to show him the awesomeness of programming. I'll have to code with the school computer and Dev C++ IDE. I don't think he's that patient so they should be done in 10 minutes.
Thanks
1
2
3
4
5
6
7
#include <iostream>

int main()
{
    std::cout << "Hello, world!" << std::endl;
    return 0;
}
My favorite trick is this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <fstream>

int main(){
    const unsigned N = 1 << 9;
    unsigned char *buffer = new unsigned char[N*N];
    for (unsigned y = 0; y < N; y++){
        for (unsigned x = 0; x < N; x++){
            buffer[x + y * N] = (x & y) ? 0xFF : 0;
        }
    }
    {
        std::ofstream output("sierpinski.raw", std::ios::binary|std::ios::trunc);
        output.write((const char *)buffer, N*N);
    }
    delete[] buffer;
    return 0;
}
Open sierpinki.raw in something like IrfanView.
He knows nothing about coding so he doesn't care about the code. He just needs some cool program. That's all.

To helios: I've installed IrfanView and opened the RAW file. IrfanView said that it couldn't decode the file or something like that.
Last edited on
It should ask for certain parameters like width, height, and pixel encoding. It's a 512x512 8-bit bitmap.
Show him Skyrim, that's a pretty cool program.
Ask him: "What's your favourite game?"
He replies say "X".
Tell him: "'X' was made using programming. Programming is awesome because you get results like 'X'. You can make your computer do anything you want with programming, all your evil things!".

Simple as that :). Most people get like "Meh...that's so old school." when they see a console program however amazing you make it. And you can't create such an amazing program with all those shine and polish in just 10 minutes...so take some time from him and create a game over a week and show him that.
One line FizzBuzz solution:
1
2
3
4
5
6
7
#include <cstdio>

int main()
{
    for (int i = 0; i < 20; ++i)
        std::printf("%d\0\0\0Fizz\0Buzz\0FizzBuzz" + !(i % 3) * 5 + !(i % 5) * 10, i);
}
Topic archived. No new replies allowed.