Ambigous

I have Ambigous error in my code both variables are global and one is a two dimensional array and the other is enum , what is wrong , i could post the whole code if it's not clear enough

post the whole code please
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
// factorial calculator
#include <iostream>
#include<conio.h>
#include<string>
using namespace std;
	int row,column=0;
	char floor[20][20]; 
	bool pen =false;
	bool running = true ;
	bool direction[2]={false};
enum Flag  {right,left,up,down};
Flag go = up ;
int posx , posy=0;

void SetArray()
{
	for (int r=0;r<20;r++)
	{
			 for(int c=0 ; c<20 ;c++)
			 {
				 floor[c][r]='-';
			 }
	}
	 for(int r=0 ;r<20 ;++r)
		 {
			 for(int c=0 ; c<20 ;c++)
			 {
				 cout<<floor[c][r];
			 }
			 cout<<endl;
			 
		 }
}
void SetDirection(int in)
{
	if( go==up && in ==3)
	{
		go=right;
	}
	if(go==left && in ==3)
	{
		go=up;
	}
	if(go==right && in ==3)
	{
		go=down;
	}
	if(go==down && in ==3)
	{
		go==left;
	}
	//left section
	if(go==up && in== 4)
	{
		go=left;
	}
	if(go==left && in ==4)
	{
		go=down;
	}
	if(go==right && in ==4)
	{
		go=up;
	}
	if(go==down && in== 4)
	{
		go=left;
	}
}
void Direction()
{
	if(go == up )
	{
		for(int i=0 ; i<10 ; i++)
		{
			floor[posx-i][posy]="#";
		}
	}
	if(go ==down)
	{
		for(int i=0;i<10;i++)
		{
			floor[posx+i][posy]="#";
		}
	}
	if(go==right)
	{
		for(int i=0;i<10;i++)
		{
			floor[posx][posy+i]="#";
		}
	}
	if(go==left)
	{
		for(int i=0 ; i<10; i++)
		{
			floor[posx][posy-i]="#";
		}
	}
}

int main()
{
	
	cout<<"Welcome to turtle graphics\n";
	cout<<"1 pen up \n";
	cout<<"2 pen down\n";
	cout<<"3 turn right \n";
	cout<<"4 turn left\n";
	cout<<"5 -10 Move forward 10 paces\n";
	cout<<"6 print the 20-20 array\n";
	cout<<"9 sentinel value\n";
	SetArray();

	while (running)
	 {
		cout<<"Enter value \n";
		 int value;
		 cin>>value;
		 switch(value)
		 {
		 case 1:
	     pen =false;
		 break;
		 case 2:
		 pen =true;
		 break;
		 case 3:
			SetDirection(value);
			break;
		 case 4:
			 SetDirection(value);
			 break;
		 case 5:
			 Direction();
			  break;
		 case 6:
			 for(int c=0;c<20;c++)
			 {
				 for(int r=0;r<20;r++)
				 {
					 cout<<floor[r][c];
				 }
				 cout<<endl;
			 }
			 break;
		 case 9:
			 running =false;
			 break;
		 }
		 }

	
	getch();
  return 0;
}

I am sorry it's a bit rough am making changes in it as we speak
The Question was:
(Turtle Graphics) The Logo language, which is popular among elementary school children, made the concept of turtle graphics famous. Imagine a mechanical turtle that walks around the room under the control of a C++ program. The turtle holds a pen in one of two positions, up or down. While the pen is down, the turtle traces out shapes as it moves; while the pen is up, the turtle moves about freely without writing anything. In this problem, you’ll simulate the operation of the turtle and create a computerized sketchpad as well.
Use a 20-by-20 array floor that is initialized to false. Read commands from an array that contains them. Keep track of the current position of the turtle at all times and whether the pen is currently up or down. Assume that the turtle always starts at position (0, 0) of the floor with its pen up. The set of turtle commands your program must process are shown in Fig. 7.27.
You shouldnt use std as a global namespace because of things like this.
you could solve the problem by renaming right right1 or something.
or you could remove the namespace and anything that uses it you could just prefix with std::

The reason is left and right are members of std, like if you didnt use the namespace you would need to use std::right.

The ambiguous error is due to the compiler not knowing which instance of right you are calling

Hope this helps :)

edit: its probably best to just not use the namespace, as this will also happen with other directions and i dont even know everything thats inside it so there may be more name conflicts
Last edited on
Yes it does make some difference and yes i have reduced the following code :
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
#include <iostream>
#include<conio.h>
#include<string>
int row,column=0;
	char floor[20][20]; 
void SetArray()
{
	for (int r=0;r<20;r++)
	{
			 for(int c=0 ; c<20 ;c++)
			 {
				 floor[c][r]='-';
			 }
	}
	 for(int r=0 ;r<20 ;++r)
		 {
			 for(int c=0 ; c<20 ;c++)
			 {
				std:: cout<<floor[c][r];
			 }
			 std::cout<<std::endl;
			 
		 }
}


int main()
{
	SetArray();
	bool running =true;
	while (running)
	 {
		std::cout<<"Enter value \n";
		 int value;
		 std::cin>>value;
		 switch(value)
		 {
		     case 6:
			 for(int c=0;c<20;c++)
			 {
				 for(int r=0;r<20;r++)
				 {
					std:: cout<<floor[r][c];
				 }
				std:: cout<<std::endl;
			 }
	       }
		 }

	
	getch();
  return 0;
}
Topic archived. No new replies allowed.