polyphonic music console app- Help

I'm trying to make a console application that can play pre-made songs like the Mary had a little lamb already implemented in the code but also take in custom user input to make there own song. i cant seem to get it to where the note variable assigns to the note[] array to play back the users custom notes.

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
#include<Windows.h>
#include<iostream>
#include <string>
using namespace std;

	int A = 880;
	int As = 932;
	int B = 988;
	int C = 1030;
	int Cs = 1045;
	int D = 294;
	int Ds = 311;
	int E = 330;
	int F = 698;
	int Fs = 740;
	int G = 784 ;
	int Gs = 830 ;

	int frth = 400;
	int one = 800;
	int half = 1600;
	int whole = 3200;
	void Pause()
	{
		char Ref;
		cin >> Ref;
	}
	int play(int note, int length)
{
	Beep(note,length);
	return 0;
}



	//mary had a little lamb function
void Mary()
{
	play(A,frth);
	play(G,frth);
	play(F,frth);
	play(G,frth);
	play(A,frth);
	play(A,frth);
	play(A,one);
	play(G,frth);
	play(G,frth);
	play(G,one);
	play(A,frth);
	play(C,frth);
	play(C,one);
	play(A,frth);
	play(G,frth);
	play(F,frth);
	play(G,frth);
	play(A,frth);
	play(A,frth);
	play(A,frth);
	play(A,frth);
	play(G,frth);
	play(G,frth);
	play(A,frth);
	play(G,frth);
	play(F,one);



}


int main()
{
	
	
	string note[2]; // input for notes
	int choice; // choice for main action
	int N[15]; //Array to store user custom notes
	int Nn = 1 ;
	cout << "Do you want to play mary had a little lamb or write your own music?\n" << endl;
	cout << "(1)Mary Had a Little Lamb" << endl;
	cout << "(2)Make Own Music(up to 15 notes)" << endl;
	cin >> choice;
	if(choice == 1)
	{
		Mary();
	}else if(choice == 2)
	{
	for(int x = 0; x< 15; x++)
	{
		// check for user input
		if(note[2] == "A")
		{
			N[x] = 880;
		}
		if(note[2] == "As")
		{
			N[x] = 932;
		}
		if(note[2] == "B")
		{
			N[x] = 988;
		}
		if(note[2] == "C")
		{
			N[x] = 1030;
		}
		if(note[2] == "Cs")
		{
			N[x] = 1045;
		}
		if(note[2] == "D")
		{
			N[x] = 294;
		}
		if(note[2] == "Ds")
		{
			N[x] = 311;
		}
		if(note[2] == "E")
		{
			N[x] = 330;
		}
		if(note[2] == "F")
		{
			N[x] = 698;
		}
		if(note[2] == "Fs")
		{
			N[x] = 740;
		}
		if(note[2] == "G")
		{
			N[x] = 784;
		}
		if(note[2] == "Gs")
		{
			N[x] = 830;
		}
		cout << "note" << Nn << ": " ;
	
		cin >> N[x]; // assign next array element user note input
		Nn++;
			

	}
	}
	Pause();

		
	
	
	return 0;
}
if(note[2] == "A")

Why are you specifying index 2? I also believe you want to put the input before the if statements since you'll need to have something to compare your first time, rather than wait until your second loop.

Also, in your for loop, what's the purpose of i? Why do you use x and Nn, but not i?
the reason it has an index of 2 is so it can take in variables like As (A sharp)
that way it doesn't cause an unasigned memory assignment. The Nn is New Not so it displays Note 1 then note 2 as you enter in the data and idk why i used x instead of i haha i didn't think the letter i use as a variable matters.
Nevermind about the for loop thing, I thought I saw an i in there. There is a few issues with the code to begin with. First, you need to have a seperate array just to hold the notes, it must be an int array, which is N[15]. You also need something to store user input, which I'm guess is what note[2] is for...but why are you creating an array to hold two strings? You only need one string. Also, you're not allowing the user to enter the value into the string. You have no need for Nn since you're using x in your for loop. Also, do you only plan on having 15 notes in your song? You should set it up so that you can type 0 to quit.
the reason i set it to 15 is because i didn't want to go past the memory i assigned the array but i can change it to a vector and use the push_back() function to add one every time a user enters a number.

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
#include<Windows.h>
#include<iostream>
#include <string>
using namespace std;

	int A = 880;
	int As = 932;
	int B = 988;
	int C = 1030;
	int Cs = 1045;
	int D = 294;
	int Ds = 311;
	int E = 330;
	int F = 698;
	int Fs = 740;
	int G = 784 ;
	int Gs = 830 ;

	int frth = 400;
	int one = 800;
	int half = 1600;
	int whole = 3200;
	void Pause()
	{
		char Ref;
		cin >> Ref;
	}
	int play(int note, int length)
{
	Beep(note,length);
	return 0;
}



	//mary had a little lamb function
void Mary()
{
	play(A,frth);
	play(G,frth);
	play(F,frth);
	play(G,frth);
	play(A,frth);
	play(A,frth);
	play(A,one);
	play(G,frth);
	play(G,frth);
	play(G,one);
	play(A,frth);
	play(C,frth);
	play(C,one);
	play(A,frth);
	play(G,frth);
	play(F,frth);
	play(G,frth);
	play(A,frth);
	play(A,frth);
	play(A,frth);
	play(A,frth);
	play(G,frth);
	play(G,frth);
	play(A,frth);
	play(G,frth);
	play(F,one);



}
void playC(int n1,int n2,int n3,int n4,int n5,int n6,int n7,int n8,int n9,int n10,int n11,int n12,int n13,int n14,int n15)
{
	play(n1,frth);
	play(n2,frth);
	play(n3,frth);
	play(n4,frth);
	play(n5,frth);
	play(n6,frth);
	play(n7,frth);
	play(n8,frth);
	play(n9,frth);
	play(n10,frth);
	play(n11,frth);
	play(n12,frth);
	play(n13,frth);
	play(n14,frth);
	play(n15,frth);
}

int main()
{
	
	
	string note; // input for notes
	int choice; // choice for main action
	int N[15]; //Array to store user custom notes
	int Nn = 1 ;
	cout << "Do you want to play mary had a little lamb or write your own music?\n" << endl;
	cout << "(1)Mary Had a Little Lamb" << endl;
	cout << "(2)Make Own Music(up to 15 notes)" << endl;
	cin >> choice;
	while(choice != -1)
	{
	if(choice == 1)
	{
		Mary();
	}
	if (choice == 2)
	{
	for (int x = 0; x < 15; x++)
	{
		if(note == "A")
		{
			N[x] = 880;
		}
		if(note == "As")
		{
			N[x] = 932;
		}
		if(note == "B")
		{
			N[x] = 988;
		}
		if(note == "C")
		{
			N[x] = 1030;
		}
		if(note == "Cs")
		{
			N[x] = 1045;
		}
		if(note == "D")
		{
			N[x] = 294;
		}
		if(note == "Ds")
		{
			N[x] = 311;
		}
		if(note == "E")
		{
			N[x] = 330;
		}
		if(note == "F")
		{
			N[x] = 698;
		}
		if(note == "Fs")
		{
			N[x] = 740;
		}
		if(note == "G")
		{
			N[x] = 784;
		}
		if(note == "Gs")
		{
			N[x] = 830;
		}
		cout << "enter a note: ";
		cin >> N[x]; cin.ignore(1,1);


	}
	playC(N[0],N[1],N[2],N[3],N[4],N[5],N[6],N[7],N[8],N[9],N[10],N[11],N[12],N[13],N[14]);
	}
	}
	
	Pause();

		
	
	
	return 0;
}



Can you find the problem in this try to run it it asks and then as soon as you enter in the letter it dosnt treat the letter as a int but a char and just skips right though with one high tome but if you manually enter in the value it works just fine
Because you're comparing note, to another string. But you never assign note anywhere. I believe your cin should be cin >> note.
I GOT IT WOOHOO!!!! Thank you for your help :) I'm going to work on the code some more and when its finished I'm going to post the final source one the general c++ forum and people can mess with it and stuff. probably some time tommorow :D
Just another interesting thing I found. If you want a note to go up an octave you multiply by 2, down and octive you divide by 2. =]
Really? I figured you would have to square/square root it.
well ever note is set to an int of hz so really any operation you do will change the pitch like A = 880 Hz if you Set A to A = (A*2) it equals 1760 Hz that is why it gets higher.
Topic archived. No new replies allowed.