hey guys, here's my problem: I'm getting an imput in form of a char variable and an int variable. The inputs will be similar to A1 A4 A7 B2 B4 B6...and so on.
I'm putting the letter into a char var and the number into int, than I'm trying to match these two some global variables. To do this I want to use switch, but when I do switch(letter+number) and then the the cases, after a while I'm getting an error message saying that "this value has been allready used. Please help in finding a way to do this...
here is the code
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
//declaring global variables to hold the positions on the board
char p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12;
char p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24;
//function displaying the board
void displayBoard()
{
cout << "\n\n";
cout << " 1 2 3 4 5 6 7\n\n"
<< "A "<<p1<<"........"<<p2<<"........"<<p3<<" A\n"
<< " . . .\n"
<< "B . "<<p4<<"....."<<p5<<"....."<<p6<<" . B\n"
<< " . . . . .\n"
<< "C . . "<<p7<<".."<<p8<<".."<<p9<<" . . C\n"
<< " . . . . . .\n"
<< "D "<<p10<<".."<<p11<<".."<<p12<<" "<<p13<<".."<<p14<<".."<<p15<<" D\n"
<< " . . . . . .\n"
<< "E . . "<<p16<<".."<<p17<<".."<<p18<<" . . E\n"
<< " . . . . .\n"
<< "F . "<<p19<<"....."<<p20<<"....."<<p21<<" . F\n"
<< " . . .\n"
<< "G "<<p22<<"........"<<p23<<"........"<<p24<<" G\n\n"
<< " 1 2 3 4 5 6 7\n"
<< endl;
}
void matchPosition(char letter, int number)
{
switch(letter, number){
case 'A'+1: case 'a'+1: p1='x'; break;
case 'A'+4: case 'a'+4: p2='x'; break;
case 'A'+7: case 'a'+7: p3='x'; break;
case 'B'+2: case 'b'+2: p4='x'; break;
case 'B'+4: case 'b'+4: p5='x'; break;
case 'B'+6: case 'b'+6: p6='x'; break;
case 'C'+3: case 'c'+3: p7='x'; break;
case 'C'+4: case 'c'+4: p8='x'; break;
case 'C'+5: case 'c'+5: p9='x'; break;
case 'D'+1: case 'd'+1: p10='x'; break;
case 'D'+2: case 'd'+2: p11='x'; break;
case 'D'+3: case 'd'+3: p12='x'; break;
case 'D'+5: case 'd'+5: p13='x'; break;
case 'D'+6: case 'd'+6: p14='x'; break;
case 'D'+7: case 'd'+7: p15='x'; break;
case 'E'+3: case 'e'+3: p16='x'; break;
case 'E'+4: case 'e'+4: p17='x'; break;
case 'E'+5: case 'e'+5: p18='x'; break;
case 'F'+2: case 'f'+2: p19='x'; break;
case 'F'+4: case 'f'+4: p20='x'; break;
case 'F'+6: case 'f'+6: p21='x'; break;
case 'G'+1: case 'g'+1: p22='x'; break;
case 'G'+4: case 'g'+4: p23='x'; break;
case 'G'+7: case 'g'+7: p24='x'; break;*/
}
//cout << letter << number;
}
//function displaying prompt and storring player's move
void displayPromptAndGetMove(){
int column;
char row;
cout << "\nEnter a move position: ";
cin >> row >> column;
matchPosition(row, column);
}
int main(){
//setting all the global variables equal a period (.)
p1 = p2 = p3 = p4 = p5 = p6 = p7 = p8 = p9 = p10 = p11 = p12 = '.';
p13 = p14 = p15 = p16 = p17 = p18 = p19 = p20 = p21 = p22 = p23 = p24 = '.';
bool notDone = true;
displayBoard();
while(notDone){
displayPromptAndGetMove();
displayBoard();
}
return 0;
}
thanks,
axon
P.S. by the way, I can't use arrays for this one :-(