Hey guys
I am in the very early stages of attempting the infimous Logo program in C++ using the imaginary turtle.
What I have compiles ok, but when I am testing if the pen is rasied up or down I am getting the wrong messages returned by the function. Oh and is it safe to use references on boolean variables like I have done? My compiler didn't complain. I only did this to ensure I got the right string returned.
Basically, if the pen is down, and i ask it to raise it up it only returns "The pen is alresdy up!" when i want it to return "The pen is raised up"
Here is all I have so far. I just want to get this part working ok first before I get on with the more complex part using the 2d array.
Code:
#include <iostream>
#include <string>
// function prototypes
int displayMenu ( const int[][ 20 ] );
std::string checkPenUp ( bool& );
std::string checkPenDown ( bool& );
// main - begins program execution /////////////////////////////////////////////
//
int main(int argc, char *argv[])
{
const int MAX_ROW = 20;
const int MAX_COL = 20;
const int board[ MAX_ROW ][ MAX_COL ] = { 0 };
displayMenu ( board );
std::cin.get(); // freeze console output window
return 0; // return value from main to OS
}
// function to display main options menu
int displayMenu ( const int brd[][ 20 ] )
{
int choice;
bool penPos = false; // pen is raised up to start with
do
{
std::cout << "\tSelect an option:\n\n"
<< "1 Raise Pen Up\n"
<< "2 Lower Pen Down\n"
<< "3 Turn Right\n"
<< "4 Turn Left\n"
<< "5 Move By Entered Values\n"
<< "6 Print Image\n"
<< "9 Quit Program\n";
std::cin >> choice;
switch ( choice )
{
case 1:
std::cout << checkPenUp ( penPos );
break;
case 2:
std::cout << checkPenDown ( penPos );
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 9:
return 0;
break;
default:
break;
}
} while ( choice );
}
// function to check if pen is raised up
std::string checkPenUp ( bool &rPen )
{
std::string str1 = "The pen has been raised up\n";
std::string str2 = "The pen is already raised up!\n";
if ( rPen == false )
{
return str2;
}
else
{
rPen = true;
return str1;
}
}
// function to check if pen is raised down
std::string checkPenDown ( bool &rPen )
{
std::string str1 = "The pen has been placed down\n";
std::string str2 = "The pen is already placed down!\n";
if ( rPen == true )
{
return str2;
}
else
{
rPen = false;
return str1;
}
}