"Map" printing with nested for loops

I am trying to print a "treasure map" for a class. Because my program works well without the map portion, I've removed it to work on it separately. The goal is to print an O where the treasure hunter began and an x where the reassure is. However, all I'm getting is pages and pages of "O"s. What have I done wrong?

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
  
#include <iostream>
using namespace std;

int main ()
{
int StartingX = 5;
int StartingY = 7;
int TreasureX = 0;
int TreasureY = 4;

                //Display the map
                for (int MapY = 20; MapY >= 0; MapY--)
                {
                        for (int MapX = 0; MapX <= 20; MapX++)
                        {
                                if ((MapX = StartingX) && ( MapY = StartingY))
                                        {

                                        cout << "O";
                                        }
                                else if ((MapX = TreasureX) && (MapY = TreasureY))
                                        {
                                        cout << "X";
                                        }
                                else
                                        {
                                        cout << " ";
                                        }
                        }
                        cout << endl;
                }


return 0;
}


Thanks in advance.
MapX = StartingX

I think you might want this instead? (and in the other comparisons)

MapX == StartingX

A single = is the assignment operator.
Last edited on
That is it! Thank you so much; I'm not sure why it didn't occur to me to use the logical "==" instead of just =.
Topic archived. No new replies allowed.