#code not displaying right output

27 messages · Page 1 of 1 (latest)

supple lance
#
/*
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;
}```
prime edgeBOT
#

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.

supple lance
#

This suppose to show the empty map then display one with a x in the middle

#

And the thing is still empty

limpid wadi
#

You never access vec1.at(1).at(1)

#

After the line vec1.at(1).at(1) = 'X'; You did a mistake

upper dragon
#

even before that the same problem is there

mint moth
#

Not just this one, start with:

{
    {'1', '2', '3'},
    {'4', '5', '6'},
    {'7', '8', '9'}
};

and you'll easily notice what's wrong.

supple lance
#

Yes I found out

#

I left the rest at row column

#

0

#

I fixed it thanks

upper dragon
#

row 0

supple lance
#

Yes

upper dragon
#

If you used debugger, you could have easily fixed this mistake

#

just keep it in mind for the future

supple lance
#

I have a debugger in vs studio

#

Sometimes it doesnt show anything

upper dragon
#

Are you putting a breakpoint and stepping over or stepping into lines of code?

supple lance
#

No

upper dragon
#

Because it always works and shows the values of things for me

supple lance
#

Ima need to look at tutorial on utube

upper dragon
#

You can also look up visual studio debugger on Google and they have a nice tutorial for you

supple lance
#

👍

#

!solved