/*
treasure project
place an x in the middle of the map
*/
#include <iostream>
#include <vector>
int main(){
std::vector<std::vector<char>>vec1 // you cant use auto in template argument
{
{' ', ' ', ' '},
{' ', ' ', ' '},
{' ', ' ', ' '}
};
std::cout << "This is a treasure map! " << std::endl;
std::cout << vec1.at(0).at(0) << " " << vec1.at(0).at(1) << " " << vec1.at(0).at(2) << std::endl;
std::cout << vec1.at(1).at(0) << " " << vec1.at(0).at(1) << " " << vec1.at(0).at(2) << std::endl;
std::cout << vec1.at(2).at(0) << " " << vec1.at(0).at(1) << " " << vec1.at(0).at(2) << std::endl;
std::cout << "Place an x in the middle of the map" << std::endl;
vec1.at(1).at(1) = 'X';
std::cout << vec1.at(0).at(0) << " " << vec1.at(0).at(1) << " " << vec1.at(0).at(2) << std::endl;
std::cout << vec1.at(1).at(0) << " " << vec1.at(0).at(1) << " " << vec1.at(0).at(2) << std::endl;
std::cout << vec1.at(2).at(0) << " " << vec1.at(0).at(1) << " " << vec1.at(0).at(2) << std::endl;
if(vec1.at(1).at(1) == 'x' || vec1.at(1).at(1) == 'X'){
std::cout << "X marks the spot";
}
else{
std::cout << "Wrong spot";
}
return 0;
}```
#code not displaying right output
27 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
This suppose to show the empty map then display one with a x in the middle
vec1.at(1).at(1) = ‘X’;
And the thing is still empty
You never access vec1.at(1).at(1)
After the line vec1.at(1).at(1) = 'X'; You did a mistake
Not just this one, start with:
{
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'}
};
and you'll easily notice what's wrong.
row 0
Yes
If you used debugger, you could have easily fixed this mistake
just keep it in mind for the future
Are you putting a breakpoint and stepping over or stepping into lines of code?
No
Because it always works and shows the values of things for me
Ima need to look at tutorial on utube
You can also look up visual studio debugger on Google and they have a nice tutorial for you