| | |
Can't find Syntax Error
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 9
Reputation:
Solved Threads: 0
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!!
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!!
c Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; int main() { unsigned int board = 511; unsigned int mask = 256; int i, j; int number; do { cout << "Press a number [1-9 or 0 to quit]:"; cin>> number; switch (number) { case 1: board = board ^ 416; // if (input == 1) then (switch 1,2,4) break; case 2: board = board ^ 464; // if (input == 2) then (switch 1,2,3,5) break; case 3: board = board ^ 200; // if (input == 3) then (switch 2,3,6) break; case 4: board = board ^ 308; // if (input == 4) then (switch 1,4,5,7) break; case 5: board = board ^ 186; // if (input == 5) then (switch 2,4,5,6,8) break; case 6: board = board ^ 89; // if (input == 6) then (switch 3,5,6,9) break; case 7: board = board ^ 38; // if (input == 7) then (switch 4,7,8) break; case 8: board = board ^ 39; // if (input == 8) then (switch 4,7,8,9) break; case 9: board = board ^ 11; // if (input == 9) then (switch 6,8,9) break; } for (i=0; i<3; i++) { for (j=0; j<3; j++) { if ((board & mask) == 0) cout << "0"; else cout << "1"; mask = mask >> 1; } while (board!=0); } { if (board == 0)cout << "YOU WIN" << endl; } cout << endl; } return 0; }
Last edited by WolfPack; Nov 8th, 2006 at 2:23 am.
•
•
•
•
I've been working on it for hours and have gotten it down to one syntax error
c Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; int main() { unsigned int board = 511; unsigned int mask = 256; int i, j; int number; do { cout << "Press a number [1-9 or 0 to quit]:"; cin>> number; switch (number) { case 1: board = board ^ 416; // if (input == 1) then (switch 1,2,4) break; case 2: board = board ^ 464; // if (input == 2) then (switch 1,2,3,5) break; case 3: board = board ^ 200; // if (input == 3) then (switch 2,3,6) break; case 4: board = board ^ 308; // if (input == 4) then (switch 1,4,5,7) break; case 5: board = board ^ 186; // if (input == 5) then (switch 2,4,5,6,8) break; case 6: board = board ^ 89; // if (input == 6) then (switch 3,5,6,9) break; case 7: board = board ^ 38; // if (input == 7) then (switch 4,7,8) break; case 8: board = board ^ 39; // if (input == 8) then (switch 4,7,8,9) break; case 9: board = board ^ 11; // if (input == 9) then (switch 6,8,9) break; } for (i=0; i<3; i++) { for (j=0; j<3; j++) { if ((board & mask) == 0) cout << "0"; else cout << "1"; mask = mask >> 1; } }// was missing }// was missing while (board!=0); // } is extra // { not needed if (board == 0) cout << "YOU WIN" << endl; // } is extra cout << endl; // } not needed return 0; }
バルサミコ酢やっぱいらへんで
•
•
Join Date: Oct 2006
Posts: 9
Reputation:
Solved Threads: 0
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!
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!
![]() |
Similar Threads
- Helllppp..> <<invalid Syntax Error>> (Viruses, Spyware and other Nasties)
- syntax error: i cant find it..HELP! (ASP)
- IE Syntax Error and Can´t browse some sites (Viruses, Spyware and other Nasties)
- Invalid Syntax Error (Viruses, Spyware and other Nasties)
- declaration syntax error? (C++)
- syntax error that I just can't seem to find! (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: i need help to encrypt characters
- Next Thread: How to clear a part of screen?
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






