Can't find Syntax Error

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 9
Reputation: confused! is an unknown quantity at this point 
Solved Threads: 0
confused! confused! is offline Offline
Newbie Poster

Can't find Syntax Error

 
0
  #1
Nov 8th, 2006
Hello all!

I'm having trouble with my homework assignment - I've been working on it for hours and have gotten it down to one syntax error and then I think it will compile so I can move on, I just can't seem to figure out what the problem is. Here is my code.... THANKS!!

  1.  
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. int main()
  6. {
  7. unsigned int board = 511;
  8. unsigned int mask = 256;
  9. int i, j;
  10. int number;
  11. do {
  12. cout << "Press a number [1-9 or 0 to quit]:";
  13. cin>> number;
  14. switch (number)
  15. {
  16.  
  17. case 1: board = board ^ 416; // if (input == 1) then (switch 1,2,4)
  18. break;
  19. case 2: board = board ^ 464; // if (input == 2) then (switch 1,2,3,5)
  20. break;
  21. case 3: board = board ^ 200; // if (input == 3) then (switch 2,3,6)
  22. break;
  23. case 4: board = board ^ 308; // if (input == 4) then (switch 1,4,5,7)
  24. break;
  25. case 5: board = board ^ 186; // if (input == 5) then (switch 2,4,5,6,8)
  26. break;
  27. case 6: board = board ^ 89; // if (input == 6) then (switch 3,5,6,9)
  28. break;
  29. case 7: board = board ^ 38; // if (input == 7) then (switch 4,7,8)
  30. break;
  31. case 8: board = board ^ 39; // if (input == 8) then (switch 4,7,8,9)
  32. break;
  33. case 9: board = board ^ 11; // if (input == 9) then (switch 6,8,9)
  34. break;
  35. }
  36. for (i=0; i<3; i++)
  37.  
  38. {
  39. for (j=0; j<3; j++)
  40. {
  41.  
  42. if ((board & mask) == 0) cout << "0";
  43. else cout << "1";
  44. mask = mask >> 1;
  45. }
  46. while (board!=0); }
  47. {
  48. if (board == 0)cout << "YOU WIN" << endl;
  49.  
  50. }
  51. cout << endl;
  52.  
  53. }
  54.  
  55. return 0;
  56. }
Last edited by WolfPack; Nov 8th, 2006 at 2:23 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Can't find Syntax Error

 
0
  #2
Nov 8th, 2006
Originally Posted by confused! View Post
I've been working on it for hours and have gotten it down to one syntax error
Next time, please give the syntax error. If you had learnt to properly indent your code, you wouldn't have got this error. Here is the corrected code.
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main()
  5. {
  6. unsigned int board = 511;
  7. unsigned int mask = 256;
  8. int i, j;
  9. int number;
  10. do
  11. {
  12. cout << "Press a number [1-9 or 0 to quit]:";
  13. cin>> number;
  14. switch (number)
  15. {
  16. case 1:
  17. board = board ^ 416; // if (input == 1) then (switch 1,2,4)
  18. break;
  19. case 2:
  20. board = board ^ 464; // if (input == 2) then (switch 1,2,3,5)
  21. break;
  22. case 3:
  23. board = board ^ 200; // if (input == 3) then (switch 2,3,6)
  24. break;
  25. case 4:
  26. board = board ^ 308; // if (input == 4) then (switch 1,4,5,7)
  27. break;
  28. case 5:
  29. board = board ^ 186; // if (input == 5) then (switch 2,4,5,6,8)
  30. break;
  31. case 6:
  32. board = board ^ 89; // if (input == 6) then (switch 3,5,6,9)
  33. break;
  34. case 7:
  35. board = board ^ 38; // if (input == 7) then (switch 4,7,8)
  36. break;
  37. case 8:
  38. board = board ^ 39; // if (input == 8) then (switch 4,7,8,9)
  39. break;
  40. case 9:
  41. board = board ^ 11; // if (input == 9) then (switch 6,8,9)
  42. break;
  43. }
  44. for (i=0; i<3; i++)
  45. {
  46. for (j=0; j<3; j++)
  47. {
  48. if ((board & mask) == 0)
  49. cout << "0";
  50. else
  51. cout << "1";
  52. mask = mask >> 1;
  53. }
  54. }// was missing
  55. }// was missing
  56. while (board!=0);
  57. // } is extra
  58. // { not needed
  59. if (board == 0)
  60. cout << "YOU WIN" << endl;
  61.  
  62. // } is extra
  63. cout << endl;
  64.  
  65. // } not needed
  66.  
  67. return 0;
  68. }
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 9
Reputation: confused! is an unknown quantity at this point 
Solved Threads: 0
confused! confused! is offline Offline
Newbie Poster

Re: Can't find Syntax Error

 
0
  #3
Nov 8th, 2006
Thanks for the help! I am still so confused. The board is suppose to look like this at the beginning:

111
111
111

and then when a number is pressed all numbers up, down and to each side of it will change including the number pressed. So, if a 5 is pressed at this point the board will look like this

101
000
101

and then if a 1 is pressed it will switch to this
011
100
101
and so forth.....

I had been able to have the print of the board working until I started adding code to it to try to get it to loop back up to the top until someone can make the board have all zeros (that is how the "game" is won).

Can you give me some insight into:

1) why isn't the board set up in 3 rows of 3 anymore
and
2) where else am I going wrong in my loop, I should be able to continue playing and pressing a number again and again until I win or press zero to quit.

Thanks!
confused!
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Can't find Syntax Error

 
0
  #4
Nov 9th, 2006
> switch (number)
With a suitable table of values (ie, an array), you could do all this with one line
board ^= table[number];
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC