The essence of the program is to simulate the snowfall in the console. It creates a two-dimensional array of type char, then fills it with spaces (clears the ''), then generates asterisks in the first line of the array and then drops them in a chaotic order. But it is in theory. In practice, it is simply the first two lines to musolize randomly creating and deleting asterisks. Help correct the error. Code below:
#include <iostream> #include <ctime> #include <Windows.h> class logo { private: int move = 0; static const int str = 10, len = 20; char game_logo[str][len]; void print_game_logo(); public: logo(); void fill_array(); void scan_game_logo (); }; using namespace std; int main() { logo gl; gl.fill_array(); while (true) { gl.scan_game_logo(); } return 0; } logo::logo() { for (int i = 0; i < str; i++) { for (int j = 0; j < len; j++) { game_logo[i][j] = ' '; } } } void logo::print_game_logo () { for (int i = 0; i < str; i++) { cout << endl; for (int j = 0; j < len; j++) { cout << game_logo[i][j]; } } Sleep(500); system("cls"); } void logo::scan_game_logo () { srand((unsigned)time(NULL)); print_game_logo(); for (int i = 0; i < (str - 1); i++) { for (int j = 0; j < len; j++) { if (game_logo[i][j] == '*') { move = rand() % 4; switch (move) { case 0: break; case 1: game_logo[i][j] = ' '; game_logo[i + 1][j] = '*'; move = 0; break; case 2: game_logo[i][j] = ' '; game_logo[i + 1][j - 1] = ' '; move = 0; break; case 3: game_logo[i][j] = ' '; game_logo[i + 1][j + 1] = ' '; move = 0; break; } } else { break; } } } for (int i = 0; i < len; i++) { game_logo[str][i] = ' '; } for (int i = 0; i < len; i++) { game_logo[0][rand() % len] = '*'; } } void logo::fill_array() { for (int i = 0; i < len; i++) { game_logo[0][rand() % len] = '*'; } }