I REALLY NEED YOUR HELP GUYS.

need some help with my problem over here! our teacher give us a task that we will do a program that prints

1st message: Merry Christmas
2nd message: Happy New Year

and that it should MOVE horizontally. I really need the codes and so that i can also understand and learn from you guys.

THANKYOU! :))
Last edited on
So what exactly does it do? Print "Merry Christmas" and "Happy New Year" in such a way them move over the screen? Could you show some example output? That way it would be easier to help understand your problem.
You could store the message as a string.

The have a loop which does the following over and over
print the string followed by carriage return '\r';
remove the first character from the string. Add it to the end of the string.
delay for a few tens or hundreds of milliseconds
Last edited on
can i see the code? because honestly i really dont know how to start this program.
can i see the code?

There is no code. I just gave some suggestions for you to try. Maybe you should have a go and then ask questions when you get stuck. Post the code you have written so far,
Example code of @Chervil's implementation could be something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
    int spaces = 0; //Used to store the number of spaces to print
    while(true) //Keep on going forever
    {
        std::cout << "\r"; //Go back to the beginning of the lien
        for(int i = 0; i < spaces; ++i)
            std::cout << " "; //Print the spaces
        std::cout << "Merry Christmas"; //Print the message
        sleep(1000); //Wait for a second
        ++spaces; //Increase the number of spaces to draw
    }
    return 0;
}


Given your terminal interprets a carriage return as a "go to the beginning of the line" command (this might not always be the case, take old Mac computers for example), this would write "Merry Christmas" that moves left every iteration. The function sleep is platform dependent, this could be Sleep on windows or sleep on Unix.
Topic archived. No new replies allowed.