Problem: The queen on the ACSL chess board is the most versatile piece. It can move at most N cells (where N is determined at the start of each game) in the following directions:

1. Left or Right to the borders of the chess board

2. Up or Down to the borders of the chess board

3. Diagonally to the borders of the chess board

r/c12345

5

4

3

2

1

Since the queen can range in so many directions to capture an opponentâ€™s pieces, where can those pieces be safely placed? The ACSL chess board will be a 5x5 grid as labeled and shown above.

Input: There will be five lines of input. Each line will give the location of the queen as an ordered pair in a row, column order and the value of N.

Output: Print the number of locations where a chess piece is safe from capture.

Sample Input:

1. 3,3,2

2. 4,1,1

3. 5,3,2

4. 5,4,3

5. 2,3,1

Sample Output:

1. 8

2. 19

3. 14

4. 13

5. 16

THIS IS WHAT I GOT SO FAR:

#include<iostream>

using namespace std;

void input(double &x,double &y,double &N)

{

cout<<"Plug in an x,y,and N value."<<endl;

cin>>x;

cin>>y;

cin>>N;

}

int calc(int x,int y,int N)

{

int cordinates=24;

for(int n=1; n<(N+1);n++)

{

if((x-n)>0)

{

cordinates--;

if((y+n)> 0)

cordinates--;

if((y-n)< 6)

cordinates--;

}

if((x+n)<6)

{

cordinates--;

if((y+n)> 0)

cordinates--;

if((y-n)< 6)

cordinates--;

}

if((y+n)> 0)

{

cordinates--;

}

if((y-n)< 6)

{

cordinates--;

}

}

return cordinates;

}

int main()

{

for(int i=0;i<5;i++)

{

double x;

double y;

double N;

int cordinates;

input(x,y,N);

cordinates =calc(x,y,N);

cout<<i+1<<". "<<cordinates<<endl;

}

return 0;

}

my problem is that i cant get 2 and 3 in the example problems to work

1. Left or Right to the borders of the chess board

2. Up or Down to the borders of the chess board

3. Diagonally to the borders of the chess board

r/c12345

5

4

3

2

1

Since the queen can range in so many directions to capture an opponentâ€™s pieces, where can those pieces be safely placed? The ACSL chess board will be a 5x5 grid as labeled and shown above.

Input: There will be five lines of input. Each line will give the location of the queen as an ordered pair in a row, column order and the value of N.

Output: Print the number of locations where a chess piece is safe from capture.

Sample Input:

1. 3,3,2

2. 4,1,1

3. 5,3,2

4. 5,4,3

5. 2,3,1

Sample Output:

1. 8

2. 19

3. 14

4. 13

5. 16

THIS IS WHAT I GOT SO FAR:

#include<iostream>

using namespace std;

void input(double &x,double &y,double &N)

{

cout<<"Plug in an x,y,and N value."<<endl;

cin>>x;

cin>>y;

cin>>N;

}

int calc(int x,int y,int N)

{

int cordinates=24;

for(int n=1; n<(N+1);n++)

{

if((x-n)>0)

{

cordinates--;

if((y+n)> 0)

cordinates--;

if((y-n)< 6)

cordinates--;

}

if((x+n)<6)

{

cordinates--;

if((y+n)> 0)

cordinates--;

if((y-n)< 6)

cordinates--;

}

if((y+n)> 0)

{

cordinates--;

}

if((y-n)< 6)

{

cordinates--;

}

}

return cordinates;

}

int main()

{

for(int i=0;i<5;i++)

{

double x;

double y;

double N;

int cordinates;

input(x,y,N);

cordinates =calc(x,y,N);

cout<<i+1<<". "<<cordinates<<endl;

}

return 0;

}

my problem is that i cant get 2 and 3 in the example problems to work

Topic archived. No new replies allowed.