Help with arrays/chars

Writing a code for my class and I've been stuck on this for a few days and makes no sense to me/my teacher.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main ()
{
	array f[]=" ";
	int ans;
	cout << "type 1 or two: ";
	cin >> ans;
	if(ans==1)
	{
		f[]="no";
	}
	if(ans==2)
	{
		f[]="ye";
	}
	cout << f;
	cin.get();
	cin.get();
}


Hard to explain what I'm trying to do, but basically making an array with words in it and being able to change what words are in it based on actions of the user, always get 20+ errors and I stopped trying because there has got to be something I don't know
Not clear if you're trying to use the standard container array or not.

If so, there are a few problems.
1) You're not including the header. #include <array>
2) You're not declaring the array correctly. array<T,N> where T is the type of the array and N is the size of the array.

If not, then array is not a valid type. You want something like char f[3] = " ";

Lines 12 and 16 don't make any sense.

Change f to type string and this should work the way you want.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
using namespace std;

int main ()
{
	string f = " ";
	int ans;
	cout << "type 1 or two: ";
	cin >> ans;
	if(ans==1)
	{
		f ="no";
	}
	if(ans==2)
	{
		f="ye";
	}
	cout << f;
	cin.get();
	cin.get();
}




Topic archived. No new replies allowed.