Trying to make simple scrolling-thingy.

For some reason, when I press that right button at startup of the program, the bar does not move right. :/

(I know there's an infinite loop.)

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
#include <iostream>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>

using namespace std;

class Scroller
{
    private:
    int Position;
    string Text;
    public:
    void MoveLeft()
    {
        Position = Position - 1;
    }
    void MoveRight()
    {
        Position = Position + 1;
    }
    Scroller(int Num)
    {
        Position = Num;
        Text = "--------";
    }
    string GetText()
    {
        return Text;
    }
    int GetPos()
    {
        return Position;
    }
};

void Draw(Scroller *Scroll)
{
    system("cls");
    if (Scroll->GetPos() == 1)
    {
        cout << Scroll->GetText();
    }
    if (Scroll->GetPos() == 2)
    {
        cout << "\t" << Scroll->GetText();
    }
}

int main()
{
    Scroller GUI(2);
    char in;
    while (true)
    {
        if (getch() == VK_LEFT)
            GUI.MoveRight();
        if (getch() == VK_RIGHT)
            GUI.MoveLeft();
        Draw(&GUI);
        Sleep(50);
    }
    return 0;
}
Last edited on
Topic archived. No new replies allowed.