943,867 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 819
  • C++ RSS
Jul 13th, 2009
0

could you help me to compile this snake game in c++

Expand Post »
C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. using std::cout;
  3. using std::cin;
  4. using std::endl;
  5. #include<conio.h>
  6. class Mouse
  7. { public:
  8. void move();
  9. void turn();
  10. };
  11. void Mouse::move()
  12. {
  13. char ch;
  14. int length;
  15. int width;
  16.  
  17. switch (ch)
  18. {
  19. case '1':
  20. cout<<"To move forward";
  21. for(int y;y==length;y--)
  22. break;
  23. case'2':
  24. for(int x;x<width;x++)
  25. break;
  26. case'3':
  27. for(int x;x>0;x--)
  28. break;
  29. }
  30. }
  31. void Mouse::turn()
  32. {
  33. for(int a=0;a<200;a++)
  34. cout<<a<<"^"<<(char)23<<endl;
  35. }
  36. int main()
  37. {
  38. int length,width;
  39. cout<<"Please enter the width of the room:";
  40. cin>>width;
  41. cout<<"Please enter the length of the room:";
  42. cin>>length;
  43. int ** myArray = 0;
  44. myArray = new int*[length];
  45. if (myArray != NULL) {
  46. for (int i = 0; i < length; i++) {
  47. myArray[i] = new int[width];
  48. cout<<"X";
  49. }
  50. }
  51. for(int x=0;x<width;x++)
  52. {
  53. for(int y=0;y<length;y++)
  54. myArray[x][y]=0;
  55. }
  56. cout<<length<<"x"<<width<<"x";
  57. int x,y;
  58. if(x<4&&y<4){
  59. myArray[3][4]=1;
  60. myArray[1][3]=1;
  61. }
  62. else
  63. cout<<"you entered wrong obstacles"<<endl;
  64. getch();
  65. return 0;
  66. }



/*The compilergives this runtime error could you solve the problem about it?

'hgh.exe': Loaded 'C:\Users\medion\Documents\Visual Studio 2008\Projects\hgh\Debug\hgh.exe', Symbols loaded.
'hgh.exe': Loaded 'C:\Windows\System32\ntdll.dll'
'hgh.exe': Loaded 'C:\Windows\System32\kernel32.dll'
'hgh.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\msvcp90d.dll'
'hgh.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\msvcr90d.dll'
Run-Time Check Failure #3 - The variable 'x' is being used without being initialized.
Run-Time Check Failure #3 - The variable 'y' is being used without being initialized.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
First-chance exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
Unhandled exception at 0x00241a0f in hgh.exe: 0xC0000005: Access violation writing location 0xabababbb.
The program '[3028] hgh.exe: Native' has exited with code 0 (0x0).*/
Last edited by Ancient Dragon; Jul 13th, 2009 at 7:25 pm. Reason: add code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beset123 is offline Offline
4 posts
since Jul 2009
Jul 13th, 2009
-1

Re: could you help me to compile this snake game in c++

lines 21 and 24: >> for(int x;x<width;x++)
You forgot the variable initializer. Should be like this: for(int x = 0;x<width;x++)
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005
Jul 13th, 2009
0

Re: could you help me to compile this snake game in c++

thanks a lot!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beset123 is offline Offline
4 posts
since Jul 2009
Jul 13th, 2009
0

Re: could you help me to compile this snake game in c++

But i couldnt create the walls of the game and comile it could you help me
Ancient Dragon
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beset123 is offline Offline
4 posts
since Jul 2009
Jul 13th, 2009
0

Re: could you help me to compile this snake game in c++

line 17: the value of ch is undefined. Similar problem with all the other variables declared in that function. Variables have to be initialized with something before using them.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: MySQL Stored procedure call in c++
Next Thread in C++ Forum Timeline: Cannot run OpenCV





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC