#include "stdafx.h"
#include <iostream>
#include <string>
#include <windows.h>
#include <time.h>
unsigned long n = 1;
int main()
{
int i = 0;
std::string text = "I whip my hair back and forth";
std::string wipIt = " ";
size_t sz;
sz = wipIt.size();
srand(time(0));
do{
for(i = 0; i < 10; i++)
{
int randomNumber = rand() % 15 + 1;
Sleep(50);
wipIt.resize (sz++,' ');
std::cout << wipIt;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), randomNumber);
std::cout << text << "\n";
}
for(i = 10; i > 0; i--)
{
int randomNumber = rand() % 15 + 1;
Sleep(50);
wipIt.resize (sz--,' ');
std::cout << wipIt;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), randomNumber);
std::cout << text << "\n";
}
}
while (n != 0);
return 0;
}
If I messed this post up I apologize this is only like my second post.
What would be the easiest way to make every character in the string a different color, instead of the entire string the same color.
Tidying up tips would be appreciated as well 😛
EDIT: tidy’d up a little, and the random is working well, thank you all ^_^ now for the color by character?
Why does it not seem random? Well, because it isn’t. Computers use pseudorandom number generators to produce seemingly random numbers which are actually well-known and determinate.
The initial state of the pseudorandom generator is called a ‘seed’; you have to set it to something different every time to produce more-close-to-random results. In C, you can do it like this:
This sets the seed to the actual time in seconds upon every call.