Music Game Not Working

I am trying to make a simple game where you guess the major/perfect interval from C. For some reason, the second interval won't play. Here is the code.1

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
#include <iostream> //for output
#include <Windows.h>//for beeps
#include <stdlib.h> //for rand
#include <conio.h>  //for clr_scr
#include <string>   //for clr_scr

using namespace std;

void clr_scr() //screen clearing function
{
	HANDLE hndl=GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	GetConsoleScreenBufferInfo(hndl, &csbi);
	DWORD written;
	DWORD N= csbi.dwSize.X*csbi.dwCursorPosition.Y+csbi.dwCursorPosition.X+1;
	COORD curhome={0,0};

	FillConsoleOutputCharacter(hndl, '  ', N, curhome, &written);
	csbi.srWindow.Bottom-=csbi.srWindow.Top;
	csbi.srWindow.Top=0;
	SetConsoleWindowInfo(hndl, TRUE, &csbi.srWindow);
	SetConsoleCursorPosition(hndl,curhome);
}

int main()
{
    int note = 1;

        int guess = 0;
        note = rand() + 1 % 8; //randomizes interval
        while(1) {
        cout << "Guess the interval." << endl;
        Sleep(800);
        Beep(262,800); // middle C

        switch(note)
        {
            case 1:
                    Beep(262,800);
                    cin >> guess;
                    if (guess == 1)
                        cout << endl << "Correct!";
                    else
                        cout << endl << "Wrong!";
                    break;
            case 2:
                    Beep(294,800);
                    cin >> guess;
                    if (guess == 2)
                        cout << endl << "Correct!";
                    else
                        cout << endl << "Wrong!";
                    break;
            case 3:
                    Beep(300,800);
                    cin >> guess;
                    if (guess == 3)
                        cout << endl << "Correct!";
                    else
                        cout << endl << "Wrong!";
                    break;
            case 4:
                    Beep(349,800);
                    cin >> guess;
                    if (guess == 4)
                        cout << endl << "Correct!";
                    else
                        cout << endl << "Wrong!";
                    break;
            case 5:
                    Beep(392,800);
                    cin >> guess;
                    if (guess == 5)
                        cout << endl << "Correct!";
                    else
                        cout << endl << "Wrong!";
                    break;
            case 6:
                    Beep(440,800);
                    cin >> guess;
                    if (guess == 6)
                        cout << endl << "Correct!";
                    else
                        cout << endl << "Wrong!";
                    break;
            case 7:
                    Beep(494,800);
                    cin >> guess;
                    if (guess == 7)
                        cout << endl << "Correct!";
                    else
                        cout << endl << "Wrong!";
                    break;
            case 8:
                    Beep(523,800);
                    cin >> guess;
                    if (guess == 8)
                        cout << endl << "Correct!";
                    else
                        cout << endl << "Wrong!";
                    break;
        }
        clr_scr(); }

}
First off, shouldn't it be (rand() % 8) +1 ? Then you get desired range. With yours, I guess you will get numbers from 0 to 7.
And if rand initially gave you 0, then it might be the problem - rand will be the same in every program, because you don't initialize seed(srand).
Also, if you are using C++, then I would recommend using some random number generator from <random> library. These are better in being random then rand.

And program looks a bit strange in its logic to me, but idk how Beep works. Try Beep by itself. If it doesn't work and nobody answers here, go to Windows subforum - because problem is windows programming related, rather then C++ related.

Cheers!
Topic archived. No new replies allowed.