Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
// ConsoleApplication5.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <string.h>
#include <string>
#include <cstdlib>


//aray variables
char ri_ght;
char bottom;
char le_ft;

//temp variable storage
//temp variable storage

//ending of array variables

using namespace std;

string map[6][6];

int printmap(){

    string top = "X";

    // top border
    map[0][0] = top;
    map[1][0] = top;
    map[2][0] = top;
    map[3][0] = top;
    map[4][0] = top;
    map[5][0] = top;
    map[6][0] = top;
    //top border

    //right side
    map[6][1] = ri_ght;
    map[6][2] = ri_ght;
    map[6][3] = ri_ght;
    map[6][4] = ri_ght;
    map[6][5] = ri_ght;
    map[6][6] = ri_ght;
    //right side

    //bottom
    map[5][6] = bottom;
    map[4][6] = bottom;
    map[3][6] = bottom;
    map[2][6] = bottom;
    map[1][6] = bottom;
    map[0][6] = bottom;
    //bottom

    //left
    map[0][5] = le_ft;
    map[0][4] = le_ft;
    map[0][3] = le_ft;
    map[0][2] = le_ft;
    map[0][1] = le_ft;
    //left

    //print part

    cout<< map[0][0], map[1][0], map[2][0], map[3][0], map[4][0], map[5][0], map[6][0];
    cout<< "" <<endl;

    return 0;
}

int main()
{
    string test;
    string end1;

    cout<< "Test Print"<<endl;
    cin>> test;

    if (test=="yes"){
        printmap;
    }

    cin>> end1;

    return 0;
}


C++



___________________________________________

Sorry, I'm somewhat new to programming.

My intentions were if the user typed yes that it would call the function printmap and would follow that code and print out the values in the array it was told but it is not. There are no errors and the console does not doing anything when you type in yes.

I appreciate any advice.
Posted

In C++ round braces are mandatory in function calls.
Change from
Quote:

if (test=="yes"){
printmap;
}
to
C++
if (test=="yes"){
    printmap();
}



You should also change from
Quote:
string map[6][6];
to
string map[7][7];

in order to avoid buffer overrun.


Finally this line, probably is not what you actually wanted to write, it
cout<< map[0][0], map[1][0], map[2][0], map[3][0], map[4][0], map[5][0], map[6][0];

only outputs the last item (map[6][0]) (see comma operator at Wikipedia[^]).
You possibly intended:
C++
cout<< map[0][0] << " " << map[1][0] << " " < < map[2][0] << " " << map[3][0] << " " << map[4][0] << " " << map[5][0] << " " << map[6][0];
 
Share this answer
 
v3
Comments
OriginalGriff 6-Jan-14 15:31pm    
You beat me to it! :laugh:
(I was busy looking up the /WX option, is my excuse)
BTW: I accidentally hit "1" instead of "5" - hopefully I've corrected it without adverse effects, but if your rep has gone down let me know and I'll find a way to put it back up again! Sorry... :O
CPallini 6-Jan-14 15:33pm    
Well, you have nothing to do with My Reputation, Sir!
:-D
You have look at your warnings!
You have almost certainly got something like:
warning C4551: function call missing argument list
on this line:
C++
printmap;
Beasue you are not executing the method, you are just referring to the method name.
Change it to:
C++
if (test=="yes"){
    printmap();
}
And the warning will go away, and your code will work. Well, it'll work a little better...it's not there yet!

I would very strongly suggest you add the "/WX" option to your compilation options until you are a lot more familiar with the language - it will make you fix problems like this before they become a runtime error!
 
Share this answer
 
Comments
CPallini 6-Jan-14 15:33pm    
My 5.
Member 10506844 6-Jan-14 16:26pm    
What is the/WX option.
OriginalGriff 6-Jan-14 17:06pm    
It tells the compiler to treat all warnings as errors: it won't produce an EXE file and let you run your program until you change the code so the warning goes away. With C++, it's generally a little overkill (though I run with it set full time for C#) once you know what you are doing, but for a beginner it can save a lot of hassle.
I'm on my tablet at the moment, so I can't tell you exactly how to enable it, but if you right click your project in the Solution Explorer and select "Properties" you should be able to find it fairly simply as "Treat all warnings as errors" or similar.

It may seem a little heavy, but in the early days the compiler does generally know better than you or i! :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900