Please Help My Home Work

cccc
Last edited on
Well can you manage to read in the input, and print out generation 0?

Hi salem c,

I'm afraid I can't. I tried but failed. I have to do this homework but I'm beginner. But even a little help can be very useful for me. Thanks.
Last edited on
this seems to work. I've played with it as much as i'm willing too. You aint' never going to learn like this tho

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139


void print(char a[]) {
    
    std::cout << a << "\n";
}



int main(){
     char prev[10][11]{ {"--IHH---I-"}, {"-H--------"} , {"----------"},  {"----H-----"},{"----IH----"}, {"----H-----"}, {"----H-----"} ,{"-H--------"},
        {"---------I"} , {"-HI--H---I"} 
    };
    char cpy[10][11];
    

    std::cout << "How Many Generations? enter number between 1 - 99999 " << "\n";

    int gen;
    std::cin >> gen;
   
    if (gen == 0 || gen > 99999) {
        main();
    }

    int count = 0;

    for (int count = 0; count < gen; count++) {

        if (count == 0) {
            for (int x = 0; x < 10; x++) {
                for (int y = 0; y < 11; y++) {
                    cpy[x][y] = prev[x][y];        //make copy
                }
            }
        }

        if (count > 0) {
            for (int x = 0; x < 10; x++) {
                for (int y = 0; y < 11; y++) {
                    prev[x][y] = cpy[x][y];        //copy cpy to prev...
                }
            }
        }


        for (int x = 0; x < 10; x++) {
            for (int y = 0; y < 10; y++) {
                if (x == 0 && y == 0 && prev[x][y] == 'I') {
                    if (prev[x + 1][y] == 'H') {
                        cpy[x + 1][y] = 'I';
                    }
                    if (prev[x][y + 1] == 'H') {
                        cpy[x][y + 1] = 'I';
                    }
                }
                if (x == 0 && y > 0 && y < 9 && prev[x][y] == 'I') {

                    if (prev[x + 1][y] == 'H') {
                        cpy[x + 1][y] = 'I';
                    }
                    if (prev[x][y + 1] == 'H') {
                        cpy[x][y + 1] = 'I';
                    }
                    if (prev[x][y - 1] == 'H') {
                        cpy[x][y - 1] = 'I';
                    }
                }
                if (y == 0 && x > 0 && x < 9 && prev[x][y] == 'I') {
                    if (prev[x + 1][y] == 'H') {
                        cpy[x + 1][y] = 'I';
                    }
                    if (prev[x][y + 1] == 'H') {
                        cpy[x][y + 1] = 'I';
                    }
                    if (prev[x - 1][y] == 'H') {
                        cpy[x - 1][y] = 'I';
                    }

                }
                if (y > 0 && y < 9 && x > 0 && x < 9 && prev[x][y] == 'I') {
                    if (prev[x + 1][y] == 'H') {
                        cpy[x + 1][y] = 'I';
                    }
                    if (prev[x - 1][y] == 'H') {
                        cpy[x - 1][y] = 'I';
                    }
                    if (prev[x][y + 1] == 'H') {
                        cpy[x][y + 1] = 'I';
                    }
                    if (prev[x][y - 1] == 'H') {
                        cpy[x][y - 1] = 'I';
                    }

                }
                if (x == 9 && y > 0 && y < 9 && prev[x][y] == 'I') {
                    if (prev[x - 1][y] == 'H') {
                        cpy[x - 1][y] = 'I';
                    }
                    if (prev[x][y + 1] == 'H') {
                        cpy[x][y + 1] = 'I';
                    }
                    if (prev[x][y - 1] == 'H') {
                        cpy[x][y - 1] = 'I';
                    }

                }
                if (y == 9 && x > 0 && x < 9 && prev[x][y] == 'I') {
                    if (prev[x + 1][y] == 'H') {
                        cpy[x + 1][y] = 'I';
                    }
                    if (prev[x - 1][y] == 'H') {
                        cpy[x - 1][y] = 'I';
                    }
                    if (prev[x][y - 1] == 'H') {
                        cpy[x][y - 1] = 'I';
                    }

                }
                if (y == 9 && x == 9 && prev[x][y] == 'I') {
                    if (prev[x - 1][y] == 'H') {
                        cpy[x - 1][y] = 'I';
                    }
                    if (prev[x][y - 1] == 'H') {
                        cpy[x][y - 1] = 'I';
                    }

                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {

        print(cpy[i]);
    }
}

> I'm afraid I can't. I tried but failed. I have to do this homework but I'm beginner.
So you're saying you've never ever written a program before, and this is your absolutely first homework assignment on the course that started this week?

At least post your best failure to date, then we can help you fix your knowledge gaps.

Topic archived. No new replies allowed.