Help with menu settings "C"

How to set the next view in menu speedSetings()the value that was just entered before?

With that, I mean setting the normal speed, next time the settings displays will show normal speed instead the first element which is very low.

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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/// game speed ///
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

#define KEY_LEFT 75
#define KEY_RIGHT 77
#define KEY_ENTER 13
#define KEY_ESCAPE 27
#define SELECT_END 8
#define ARRAYSIZE(sel)  (sizeof(sel) / sizeof(sel[0]))

void hideCursor();
void speedSettings();
void speedSettingsSelect(unsigned int select);
void gotoxy(int x, int y);
void testspeed();

int speed;

int main()
{
    hideCursor();
    speedSettings();
}

void speedSettings()
{
    int select = 0;
    int x;

    speedSettingsSelect(select);

    while((x = _getch()))
    {
        if(x == KEY_LEFT)
        {
            select -= 2;
            if(select < 0)
                select = 0;
            speedSettingsSelect(select);
        }
        else if(x == KEY_RIGHT)
        {
            select += 2;
            if(select > SELECT_END)
                select = SELECT_END;
            speedSettingsSelect(select);
        }
        else if(x == KEY_ENTER)
        {
            if(select <= 1)
            {
                speed = 1;
                testspeed();
            }
            else if(select <= 2)
            {
                speed = 2;
                testspeed();
            }
            else if(select <= 4)
            {
                speed = 3;
                testspeed();
            }
            else if(select <= 6)
            {
                speed = 4;
                testspeed();
            }
            else if(select <= 8)
            {
                speed = 5;
                testspeed();
            }
        }
        else if(x == KEY_ESCAPE)
        {
            system("cls");
            gotoxy(44, 40);
            printf("Exiting Speed program\n");
            Sleep(500);
            exit(0);
        }
    }
}

void speedSettingsSelect(unsigned int select)
{
    const char *selection1[] =
    {
        "\n\t\t\t\t\t\t\tVERY LOW",
        "\n\t\t\t\t\t\t\tvery low",
        "    LOW",
        "    low",
        "    NORMAL",
        "    normal",
        "    HIGH",
        "    high",
        "    VERY HIGH",
        "    very high",
    };

    const char *selection[] =
    {
        "\t    |__________",
        "\t    _________",
        "|__________",
        "_________",
        "|__________",
        "_________",
        "|__________",
        "_________",
        "_|",
        "",
    };

    unsigned int i;

    system("cls");
    gotoxy(41, 4);
    printf("~~~~~~ Game options ~~~~~~");
    printf("\n\n\t\t        music\n\n\n");

    for(i = 0; i < ARRAYSIZE(selection1); i += 2)
    {
        if(i == select)
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
            printf("%s", selection1[i]);
        }
        else
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
            printf("%s", selection1[i + 1]);
        }
    }

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
    printf("\n\t\t     >  GAME SPEED");
    printf("  --------------->  ");

    for(i = 0; i < ARRAYSIZE(selection); i += 2)
    {
        if(i == select)
            printf("%s", selection[i]);
        else
            printf("%s", selection[i + 1]);
    }
    printf("\n\n\n\n\n\t\t        back to menu");
}

void gotoxy(int x, int y)
{
    COORD coord;

    coord.X = x;
    coord.Y = y;

    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

void hideCursor()
{
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO info;

    info.dwSize = 100;
    info.bVisible = FALSE;

    SetConsoleCursorInfo(hOut, &info);
}

void testspeed()
{
    char GO[] = {"Game Over"};
    int c = 9;

    system("cls");
    gotoxy(50, 20);
    for(int i = 0; i < c; i++)
    {
        printf("%c", GO[i]);
        if(speed == 1)
            Sleep(1000);
        else if(speed == 2)
            Sleep(500);
        else if(speed == 3)
            Sleep(250);
        else if(speed == 4)
            Sleep(100);
        else if(speed == 5)
            Sleep(50);
    }
    gotoxy(43, 40);
    printf("Press any hey to return");
    _getch();

    speedSettings();
}
Last edited on
if I understood you, you want to put the word static on line 30. That will keep the value from the previous run.
static int select = 0; //first time, this is zero, next time, it is the previous value, which makes line 33 function call have the previous value, is that what you wanted?
Well I think yes.... :D I have to read more about static :|

Like I said I still have much to learn about C.. this really helped.

Thank's jonnin.. case Solved ;)
Topic archived. No new replies allowed.