| | |
been at this for 5 hrs now and can't figure it out please help...
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2006
Posts: 4
Reputation:
Solved Threads: 0
I have to create a 20 x 20 array (turtle program), I am sure you guys get these alot.. I have been working on this for way too long and I am not getting it.. I have read the chapter again and still am lost.. here is the code I have so far. I can't figure out where and how to get it to show the menu options so you can tell what you have the option of hitting to get the "turtle" to go where you want it and also how to display the grid after the turtle has moved... please help.. thank you,
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; int penup(int &pen); int pendown(int &pen); int left_turn(int &dir); int right_turn(int &dir); int move(int ¤t_y,int ¤t_x); int getcommand(int &command); const int y=20; const int x=20; int dir=1; int floor[y][x]; int current_y=0; int current_x=0; int pen=1; int moves; int command; int i; int j; int main() { int again=1; if(again==1) { int dir=1; int floor[y][x]; int current_y=0; int current_x=0; int pen=1; } for(i=0;i<=y;++i) { for(j=0;j<=x;++j) { floor[i][j]=0; } } while(again!=2) { do { if(pen==1) { cout << "current pen position is up!" << endl; } else { cout << "current pen position is down!" << endl; } if(dir==0) { cout<< "current direction is up!" << endl; } else if(dir==1) { cout << "current direction is right!" << endl; } else if (dir==2) { cout << "current direction is down!" << endl; } else if(dir==3) { cout << "current direction is left!" << endl; } cout << "current position are: (" << current_x << " ," << current_y << ")\n\n"; cout << "please enter your command: "; cin >> command; cout << "\n\n"; getcommand(command); }while(command!=9); cout << "do you want to draw again? (1=yes , 2=no)"; cin >> again; if(again!=1||2) { while(again!=1||2) { cout << "That was an incorrect input!\n" << "do you want to draw again? (1=yes , 2=no)"; cin>>again; } } } return 0; } int getcommand(int &command) { if (command==1) { penup(pen); } else if (command==2) { pendown(pen); } else if (command==3) { right_turn(dir); } else if (command==4) { left_turn(dir); } else if (command==5) { cout << "please enter how many moves you want: "; cin >> moves; move(current_y,current_x); } else if (command==6) { system("cls"); for(i=0;i<=y;++i) { for(j=0;j<=x;++j) { if(floor[i][j]==0) { cout << " "; } else if(floor[i][j]==1) { cout << "*"; } } cout << endl; } } else if (command==9) { } else { cout << "you did not put a correct command. please try again."; } return command; } int penup(int &pen) { pen=1; return pen; } int pendown(int &pen) { pen=2; return pen; } int left_turn(int &dir) { --dir; if(dir<0) { dir=3; } return dir; } int right_turn(int &dir) { ++dir; if(dir>3) { dir=0; } return dir; } int move(int ¤t_y,int ¤t_x) { if(pen==1) { if(dir==0) { while((moves>0)&&(current_y>=0)) { --current_y; --moves; } } else if(dir==1) { while((moves>0)&&(current_x<=19)) { ++current_x; --moves; } } else if(dir==2) { while((moves>0)&&(current_y<=19)) { ++current_y; --moves; } } else if(dir==3) { while((moves>0)&&(current_x>=0)) { --current_x; --moves; } } } else if(pen==2) { if(dir==0) { while((moves>0)&&(current_y>=0)) { floor[current_y][current_x]=1; --current_y; --moves; } } else if(dir==1) { while((moves>0)&&(current_x<=19)) { floor[current_y][current_x]=1; ++current_x; --moves; } } else if(dir==2) { while((moves>0)&&(current_y<=19)) { floor[current_y][current_x]=1; ++current_y; --moves; } } else if(dir==3) { while((moves>0)&&(current_x>=0)) { floor[current_y][current_x]=1; --current_x; --moves; } } } return current_y,current_x; }
Last edited by Dave Sinkula; Apr 30th, 2006 at 7:04 pm.
![]() |
Similar Threads
- hp pavilion 700 boot-up probs (Troubleshooting Dead Machines)
- Can't figure out error, wont debug (C++)
- Homework Help for C++ Beginner -- I've tried and tried, and can't figure it out!! (C++)
- 12 hrs later (Geeks' Lounge)
- help with significant figure function (C)
- simple calculations How? intHrlyRate, etc Help me (ASP)
- Cannot figure out why I'm getting these Errors (Java)
- figure this out (C++)
Other Threads in the C++ Forum
- Previous Thread: need help creating a "stack" of cards
- Next Thread: c / c++ crocover
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






