Loading
submit to reddit
May 23, 2013, 01:55:30 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome!
 
   Forum Home   Help Search Forum Login Register  
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: This is wierd  (Read 1452 times)
ubuntucuber
Newbie
*
Posts: 24


design made on computer


« on: May 07, 2009, 07:57:22 AM »

here is the code line 530 in my program:
Code:
cout << "|1|" << edit[0][0] << "|" << edit[0][1] << "|" << edit[0][2] << "|" << edit[0][3] << "|" << edit[0][4] << "|" edit[0][5] << "|" edit[0][6] << "|" << edit[0][7] << "|" << edit [0][8];
and the ouput
Quote
1>c:\users\f86sabre\documents\visual studio 2008\projects\sudokuv2\sudokuv2\sudoku.cpp(530) : error C2146: syntax error : missing ';' before identifier 'edit'
1>c:\users\f86sabre\documents\visual studio 2008\projects\sudokuv2\sudokuv2\sudoku.cpp(530) : error C2297: '<<' : illegal, right operand has type 'const char [2]'
1>c:\users\f86sabre\documents\visual studio 2008\projects\sudokuv2\sudokuv2\sudoku.cpp(530) : error C2146: syntax error : missing ';' before identifier 'edit'
1>c:\users\f86sabre\documents\visual studio 2008\projects\sudokuv2\sudokuv2\sudoku.cpp(530) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
1>c:\users\f86sabre\documents\visual studio 2008\projects\sudokuv2\sudokuv2\sudoku.cpp(530) : error C2297: '<<' : illegal, right operand has type 'const char [2]'
1>c:\users\f86sabre\documents\visual studio 2008\projects\sudokuv2\sudokuv2\sudoku.cpp(530) : error C2297: '<<' : illegal, right operand has type 'const char [2]'
1>c:\users\f86sabre\documents\visual studio 2008\projects\sudokuv2\sudokuv2\sudoku.cpp(530) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
Logged
InsAneGamer
Newbie
*
Posts: 3


« Reply #1 on: May 08, 2009, 03:00:04 AM »

Of what type is edit?


It looks like the compiler is not able 2 determine the DATA TYPE  of edit....


Logged
ubuntucuber
Newbie
*
Posts: 24


design made on computer


« Reply #2 on: May 10, 2009, 11:25:29 AM »

edit was a bool i was trying to read like an int value.

i have already fixed the problem
Logged
ubuntucuber
Newbie
*
Posts: 24


design made on computer


« Reply #3 on: May 10, 2009, 11:32:42 AM »

but now i have a new problem.
Code:
int main() {
int main[9][9] = {
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}
};
bool edit[9][9] = {
{true,true,true,true,true,true,true,true,true},
{true,true,true,true,true,true,true,true,true},
{true,true,true,true,true,true,true,true,true},
{true,true,true,true,true,true,true,true,true},
{true,true,true,true,true,true,true,true,true},
{true,true,true,true,true,true,true,true,true},
{true,true,true,true,true,true,true,true,true},
{true,true,true,true,true,true,true,true,true},
{true,true,true,true,true,true,true,true,true}
};
        cout << "|*|0 |1 |2 ||3 |4 |5 ||6 |7 |8 |" << endl;
cout << "+-+--+--+--++--+--+--++--+--+--+" << endl << "|0|";
for (int iCol = 0; iCol < 9; ++iCol) {
for (int iRow = 0; iRow < 9; ++iRow) {
cout << main[iCol][iRow];
if (edit[iCol][iRow] == true) {
cout << " |";
} else {
cout << "!|";
}
if (iRow == 2 || iRow == 5) {
cout << "|";
}
}
cout << endl << "+-+--+--+--++--+--+--++--+--+--+" << endl;
if (iCol == 2) {
cout << "+-+--+--+--++--+--+--++--+--+--+" << endl;
}
if (iCol == 5) {
cout << "+-+--+--+--++--+--+--++--+--+--+" << endl;
}
cout << "|" << iCol + 1 << "|";
}
output:
Code:
|*|0 |1 |2 ||3 |4 |5 ||6 |7 |8 |
+-+--+--+--++--+--+--++--+--+--+
|0|0 |0 |0 ||0 |0 |0 ||0 |0 |0 |
+-+--+--+--++--+--+--++--+--+--+
|1|0 |0 |0 ||0 |0 |0 ||0 |0 |0 |
+-+--+--+--++--+--+--++--+--+--+
|2|0 |0 |0 ||0 |0 |0 ||0 |0 |0 |
+-+--+--+--++--+--+--++--+--+--+
+-+--+--+--++--+--+--++--+--+--+
|3|0 |0 |0 ||0 |0 |0 ||0 |0 |0 |
+-+--+--+--++--+--+--++--+--+--+
|4|0 |0 |0 ||0 |0 |0 ||0 |0 |0 |
+-+--+--+--++--+--+--++--+--+--+
|5|0 |0 |0 ||0 |0 |0 ||0 |0 |0 |
+-+--+--+--++--+--+--++--+--+--+
+-+--+--+--++--+--+--++--+--+--+
|6|0 |0 |0 ||0 |0 |0 ||0 |0 |0 |
+-+--+--+--++--+--+--++--+--+--+
|7|0 |0 |0 ||0 |0 |0 ||0 |0 |0 |
+-+--+--+--++--+--+--++--+--+--+
|8|0 |0 |0 ||0 |0 |0 ||0 |0 |0 |
+-+--+--+--++--+--+--++--+--+--+
|9|

how do you get rid of the |9| at the end and keep the for loop?
Logged
InsAneGamer
Newbie
*
Posts: 3


« Reply #4 on: May 11, 2009, 12:18:50 AM »

Instead of cout<<iCol+1 Just do cout<<iCol
Logged
Paul
Newbie
*
Posts: 14


« Reply #5 on: May 12, 2009, 03:20:57 PM »

You print the first row header, then you enter the loop and for each loop, you print the row data then the header for the next line.

Instead, print the row header at the start of the loop for that row:

Code:
cout << "|*|0 |1 |2 ||3 |4 |5 ||6 |7 |8 |" << endl;
cout << "+-+--+--+--++--+--+--++--+--+--+" << endl;
for (int iCol = 0; iCol < 9; ++iCol) {
                        cout << "[" << iCol << "]";
for (int iRow = 0; iRow < 9; ++iRow) {
cout << main[iCol][iRow];
if (edit[iCol][iRow] == true) {
cout << " |";
} else {
cout << "!|";
}
if (iRow == 2 || iRow == 5) {
cout << "|";
}
}
cout << endl << "+-+--+--+--++--+--+--++--+--+--+" << endl;
if (iCol == 2) {
cout << "+-+--+--+--++--+--+--++--+--+--+" << endl;
}
if (iCol == 5) {
cout << "+-+--+--+--++--+--+--++--+--+--+" << endl;
}
}
Logged
ubuntucuber
Newbie
*
Posts: 24


design made on computer


« Reply #6 on: May 13, 2009, 05:51:32 PM »

2 things wrong here:

Instead of cout<<iCol+1 Just do cout<<iCol

#1
InsAneGamer: the cout << iCol + 1 is necessary because then there would be 2 0's (I already tried)

#2
Paul: I fixed the problem with an if statement which worked well.
i am not trying to be rude but my solution was found about 5 minutes after  i wrote ths topic
The new code is :
Code:
for (int iCol = 0; iCol < 9; ++iCol) {
for (int iRow = 0; iRow < 9; ++iRow) {
cout << i[iCol][iRow];
if (b[iCol][iRow] == true) {
cout << " |";
} else {
cout << "!|";
}
if (iRow == 2 || iRow == 5) {
cout << "|";
}
}
cout << endl << "+-+--+--+--++--+--+--++--+--+--+" << endl;
if (iCol == 2) {
cout << "+-+--+--+--++--+--+--++--+--+--+" << endl;
}
if (iCol == 5) {
cout << "+-+--+--+--++--+--+--++--+--+--+" << endl;
}
if (iCol != 8) {
cout << "|" << iCol + 1 << "|";
}
}
Logged
Paul
Newbie
*
Posts: 14


« Reply #7 on: May 14, 2009, 10:40:56 AM »

2 things wrong here:

#2
Paul: I fixed the problem with an if statement which worked well.
i am not trying to be rude but my solution was found about 5 minutes after  i wrote ths topic

With respect, posting questions in a forum and then telling people they are wrong when they help out will not stand you in good stead if you wish to take advantage of the internet as a learning resource.

Your "solution" is also brittle as, if you change the number of rows, you have to remember to update your final if statement at the end.

But, y'know, whatever...
Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!