Screensaver problem

Hey,i'm using visual studio 2015. The task is to get an "n" number of "X" characters on the console in random positions after that the "X" characters have to move up, down,left or right one space randomly on their own, if they get to the edge they have to come out on the opposite site and it has to exit by pressing q. I'm having trouble getting them to move randomly so i would appreciate the help.

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <conio.h>
#include <ctime>
#include <stdio.h>


using namespace std;

void gotoxy(int x, int y)
{
COORD c = { x, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}


int main()
{
srand(time(0));
int n,x,y;
char ch = 'X';
char cha;
int i = 0;


cin >> n;

do {


while (i<n)
{
i++;
x = rand() % 150;
y = rand() % 20;
gotoxy(x, y);
cout << ch;


}


cha = _getch();
} while (cha != char('q') && cha!=char('Q'));


return 0;
}
Topic archived. No new replies allowed.