Help with simple GUI

I'm trying to make a simple GUI that will enlarge a character('+' specifically), when you press W and get smaller when you press S. I got it to enlarge all the way but when I make it smaller it doesn't go to the smallest. Heres my code.

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
#include <iostream>
#include <string>
#include <conio.h>
#include <Windows.h>

using namespace std;

bool play = true;

int main(){
	int i=4;
	char ch;
	string screen[8] = {
		"+-------------------", "-------------------", "--------------------+",
		"|                                                                             |",
		"|                                     ++                                      |", //4th string
		"|                                    ++++                                     |", //5th
		"|                                   ++++++                                    |", //6th
		"|                                  ++++++++                                   |"}; //7th
	do{
		//Making the GUI
		cout << screen[0] << screen[1] << screen[1] << screen[2] << endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[4] <<endl; //This is what changes
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[0] << screen[1] << screen[1] << screen[2] << endl;
		ch = getch();
		switch(ch){
		case 'w': //Makes +'s bigger
			system("CLS");
			if(i<7){
				i++;
				screen[4] = screen[i];
			}
			break;
		case 's':
			system("CLS"); //It only goes down to 4 +'s instead of 2
			if(i!=4){ 
				i--;
				screen[4] = screen[i];
			}
			break;
		}
	}while(play == true);
	return 0;
}
EDIT; Ignore this post

Change line 57 from if(i!=4){ to if(i>0){

This will let it get down to screen 0, so you'll have to change it to if(i>2){ if you only want it to get down to screen 2.
Last edited on
What's line 57 doing?

Jim
Sorry, I'm in a bad habit of not running things through my compiler before posting.
Your problem is that you are overwriting screen[4] on each output, which means the information that you originally saved to it is lost. Here's a rewrite with an 8th screen that can be rewritten over and over without loss of your original data.

This is a good start to a snake program, I haven't made one myself, but I'm pretty sure the next step is multidimensional arrays and a bit of math to figure out proper line spacing.

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
#include <iostream>
#include <string>
#include <conio.h>
#include <Windows.h>

using namespace std;

bool play = true;

int main(){
	int i=4;
	char ch;
	string screen[9] = {
		"+-------------------", "-------------------", "--------------------+",
		"|                                                                             |",
		"|                                     ++                                      |", //4th string
		"|                                    ++++                                     |", //5th
		"|                                   ++++++                                    |", //6th
		"|                                  ++++++++                                   |"}; //7th
        screen[8]=screen[4];
	do{
		//Making the GUI
		cout << screen[0] << screen[1] << screen[1] << screen[2] << endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[8] <<endl; //This is what changes
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[3] <<endl;
		cout << screen[0] << screen[1] << screen[1] << screen[2] << endl;
		ch = getch();
		switch(ch){
		case 'w': //Makes +'s bigger
			system("CLS");
			if(i<7){
				i++;
				screen[8] = screen[i];
			}
			break;
		case 's':
			system("CLS"); //It only goes down to 4 +'s instead of 2
			if(i!=4){ 
				i--;
				screen[8] = screen[i];
			}
			break;
		}
	}while(play == true);
	return 0;
}
Last edited on
Thank you so much newbieg!
Topic archived. No new replies allowed.