#include <iostream> #include <ctime> #include <cmath> #include <iomanip> using namespace std; int main() { int number = 5; char plus = '+'; char dash = '-'; char wall = '|'; for (int i = 1; i <= number; ++i) { cout << plus << dash; } cout << plus << endl; //collumn 2 int num1; char wall1 = '|'; char dash1 = '-'; srand(time(NULL)); num1 = rand() % 2; if (num1 == 1) { wall1 = '|'; dash1 = ' '; } else { dash1 = '-'; wall1 = ' '; } //collumn 3 int num2; char wall2 = '|'; char dash2 = '-'; srand(time(NULL)); num2 = rand() % 4 + 3; if (num2 == 3) { wall2 = '|'; dash2 = ' '; } else { dash2 = '-'; wall2 = ' '; } //collumn 4 int num3; char wall3 = '|'; char dash3 = '-'; srand(time(NULL)); num3 = rand() % 6 + 5; if (num3 == 5) { wall3 = '|'; dash3 = ' '; } else { dash3 = '-'; wall3 = ' '; } //collumn 5 int num4; char wall4 = '|'; char dash4 = '-'; srand(time(NULL)); num4 = rand() % 8 + 7; if (num4 == 8) { wall4 = '|'; dash4 = ' '; } else { dash4 = '-'; wall4 = ' '; } //first row cout << wall << setw(2) << wall1 << setw(2) << wall2 << setw(2) << wall3 << setw(2) << wall4 << setw(2) << wall << endl; cout << plus << " " << plus << dash1 << plus << dash2 << plus << dash3 << plus << dash4 << plus << endl; //collumn 2 int num5; char wall5 = '|'; char dash5 = '-'; srand(time(NULL)); num5 = rand() % 10+ 9; //CHANGE if (num5 == 9) { //CHANGE wall5 = '|'; dash5 = ' '; } else { dash5 = '-'; wall5 = ' '; } //collumn 3 int num6; char wall6 = '|'; char dash6 = '-'; srand(time(NULL)); num6 = rand() % 12 + 11; //CHANGE if (num6 == 11) { //CHANGE wall6 = '|'; dash6 = ' '; } else { dash6 = '-'; wall6 = ' '; } //collumn 4 int num7; char wall7 = '|'; char dash7 = '-'; srand(time(NULL)); num7 = rand() % 14 + 13; //CHANGE if (num7 == 13) { //CHANGE wall7 = '|'; dash7 = ' '; } else { dash7 = '-'; wall7 = ' '; } //collumn 5 int num8; char wall8 = '|'; char dash8 = '-'; srand(time(NULL)); num8 = rand() % 16 + 15; //CHANGE if (num8 == 15) { //CHANGE wall8 = '|'; dash8 = ' '; } else { dash8 = '-'; wall8 = ' '; } //second row cout << wall << setw(2) << wall5 << setw(2) << wall6 << setw(2) << wall7 << setw(2) << wall8 << setw(2) << wall << endl; cout << plus << " " << plus << dash5 << plus << dash6 << plus << dash7 << plus << dash8 << plus << endl; //collumn 2 int num9; char wall9 = '|'; char dash9 = '-'; srand(time(NULL)); num9 = rand() % 18 + 17; //CHANGE if (num9 == 17) { //CHANGE wall9 = '|'; dash9 = ' '; } else { dash9 = '-'; wall9 = ' '; } //collumn 3 int num10; char wall10 = '|'; char dash10 = '-'; srand(time(NULL)); num10 = rand() % 20 + 19; //CHANGE if (num10 == 19) { //CHANGE wall10 = '|'; dash10 = ' '; } else { dash10 = '-'; wall10 = ' '; } //collumn 4 int num11; char wall11 = '|'; char dash11 = '-'; srand(time(NULL)); num11 = rand() % 24 + 23; //CHANGE if (num11 == 23) { //CHANGE wall11 = '|'; dash11 = ' '; } else { dash11 = '-'; wall11 = ' '; } //collumn 5 int num12; char wall12 = '|'; char dash12 = '-'; srand(time(NULL)); num12 = rand() % 26 + 25; //CHANGE if (num12 == 25) { //CHANGE wall12 = '|'; dash12 = ' '; } else { dash12 = '-'; wall12 = ' '; } //third row cout << wall << setw(2) << wall9 << setw(2) << wall10 << setw(2) << wall11 << setw(2) << wall12 << setw(2) << wall << endl; cout << plus << " " << plus << dash9 << plus << dash10 << plus << dash11 << plus << dash12 << plus << endl; //collumn 2 int num13; char wall13 = '|'; char dash13 = '-'; srand(time(NULL)); num13 = rand() % 28 + 27; //CHANGE if (num13 == 28) { //CHANGE wall13 = '|'; dash13 = ' '; } else { dash13 = '-'; wall13 = ' '; } //collumn 3 int num14; char wall14 = '|'; char dash14 = '-'; srand(time(NULL)); num14 = rand() % 30 + 29; //CHANGE if (num14 == 29) { //CHANGE wall14 = '|'; dash14 = ' '; } else { dash14 = '-'; wall14 = ' '; } //collumn 4 int num15; char wall15 = '|'; char dash15 = '-'; srand(time(NULL)); num15 = rand() % 32+ 31; //CHANGE if (num15 == 31) { //CHANGE wall15 = '|'; dash15 = ' '; } else { dash15 = '-'; wall15 = ' '; } //collumn 5 int num16; char wall16 = '|'; char dash16 = '-'; srand(time(NULL)); num16 = rand() % 34 + 33; //CHANGE if (num16 == 33) { //CHANGE wall16 = '|'; dash16 = ' '; } else { dash16 = '-'; wall16 = ' '; } //fourth row cout << wall << setw(2) << wall13 << setw(2) << wall14 << setw(2) << wall15 << setw(2) << wall16 << setw(2) << wall << endl; cout << plus << " " << plus << dash13 << plus << dash14 << plus << dash15 << plus << dash16 << plus << endl; //fifth row cout << wall << setw(2) << " " << setw(2) << " " <<setw(2) << " " << setw(2) << " " << " " << wall << endl; cout << plus << dash << plus << dash << plus << dash << plus << dash << plus << dash << plus << endl; return 0 |
+-+-+-+-+-+-+-+-+ | | | | | + + + +-+-+-+ +-+ | | | | | + + +-+ +-+-+ +-+ | | | | | + +-+ + +-+ +-+-+ | | | | | | | | + + +-+ + + + + + | | +-+-+-+-+-+-+-+-+ |
How do I nest loops on something like this? |
|
|
Once I draw out the maze how can I knock down walls inside? |