Subliminal messages

Hi guys, I'm learning about C++. I have an assignment but I have no idea how to write it. Is there any help?
Thanks

"Write a program which alternately prints "Hello, world!" and "Buy Coca-Cola!" for fixed intervals, between screen clears, indefinitely. The "Buy Coca-Cola" message should be below the liminal threshold (the user not be able to consciously perceive it), which is about 200ms. "
Sleep(200)
Use the C++ standard library for your delays:

http://www.cplusplus.com/reference/thread/this_thread/sleep_for/
Hello monkeykid113,

I agree with PanGalactic. Sleep(200); is more a Windows specific solution and not likely to be usable on other Operating systems. The form you will want to use is:

std::this_thread::sleep_for(std::chrono::milliseconds(200));

Add the header files "chrono" and "thread" to use this.

Hope that helps,

Andy
... between screen clears ...
C++ doesn't even have the concept of a console

Reference: http://stackoverflow.com/questions/6486289/how-can-i-clear-console

Windows specific solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <thread>
#include <cstdlib>
using namespace std::chrono_literals;

void f1(){std::this_thread::sleep_for(1s); std::cout << "Hello, world \n";}
void f2(){std::this_thread::sleep_for(0.8s); std::cout <<"Don't buy Coca-Cola \n";}
void f3(){std::this_thread::sleep_for(0.02s);};

int main()
{
   for (;;)//endless loop http://stackoverflow.com/questions/20186809/endless-loop-in-c-c
   {
       f1();
       f2();
       f3();
       system("cls");
   }
}
Please don't do homework assignments for people. People need to be given the opportunity to learn. Help them to do that. Handing them the answer isn't helping anyone.
Topic archived. No new replies allowed.