Thread: easy school program

  1. #1
    Registered User
    Join Date
    May 2019
    Posts
    5

    easy school program


    "Create a program that determines which chess board fields are available to the queen from the field where it is located. The chessboard is presented as a matrix 8x8. Queen's position is entered from the keyboard into [word] [number]. And the result is saved in a string. "

    So that my assignment, which i have not be able to do on my own, if someone with good heart can help me with it i will really appreciate it .


    This is what i have did on my own but i dont know how to determinate which fields can the queen go to.
    insert
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <stdlib.h>
    
    
    int main()
    {
    	
    	int horizontal,vertical,k;
    	char poz;
    	
    	printf("Enter the horizontal position of queen(A-H)\n");
    	scanf("%s", &poz);
    	
    	if(poz=='A')
    	{
    		horizontal=1;
    	}
    	else if (poz=='B')
    	{
    		horizontal=2;
    	}	
    	else if (poz=='C')
    	{
    		horizontal=3;
    	}
    	else if (poz=='D')
    	{
    		horizontal=4;
    	}	
    	else if (poz=='E')
    	{
    		horizontal=5;
    	}
    	else if (poz=='F')
    	{
    		horizontal=6;
    	}
    	else if (poz=='G')
    	{
    		horizontal=7;
    	}
    	else if (poz=='H')
    	{
    		horizontal=8;
    	}
    	
    	printf("Enter the vertical position of queen(1-8)\n");
    	scanf("%d", vertical);
    
    
    	
    	
    	int chess[8][8]={
    	{1,2,3,4,5,6,7,8},
    	{1,2,3,4,5,6,7,8},
    	{1,2,3,4,5,6,7,8},
    	{1,2,3,4,5,6,7,8},
    	{1,2,3,4,5,6,7,8},
    	{1,2,3,4,5,6,7,8},
    	{1,2,3,4,5,6,7,8},
    	{1,2,3,4,5,6,7,8},
    	};
    
    
    }
    Last edited by powers; 05-28-2019 at 07:55 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,983
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2019
    Posts
    5
    Is this not allowed?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,983
    How To Ask Questions The Smart Way
    Sure, you can post wherever you want.

    But it comes with consequences.

    One consequence being that people who help really don't like having their time wasted.
    It is quite annoying (read: you'll be ignored) if people respond with an answer on one forum, only to discover that the same question has the same answer written by someone else on another forum.

    Pretty soon, all the helpers on all the forums you visit will mentally tag you as a cross-poster, and either ignore you or deal with your question last.
    Or just assume that someone somewhere has already answered.

    You're getting a free service, so you might want to adopt an approach that doesn't alienate the helpers.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    May 2019
    Posts
    5
    I mean i did not asked the same things on both forums tho. I didnt wanted to spam the other forum with more questions so i just decided to try other forum for my next question.

  6. #6
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,876
    iostream is c++, not C

    I'm still not sure what your assignment wants you to do - can you give us an example of how the user would use your programme?

  7. #7
    Registered User
    Join Date
    May 2019
    Posts
    5
    The user have to type cordinates on the board for the queen, and the program must return every field the queen can go to from these cordinates.

  8. #8
    Registered User catacombs's Avatar
    Join Date
    May 2019
    Location
    /home/
    Posts
    81
    powers, are you writing this program in C or C++?

  9. #9
    Registered User
    Join Date
    May 2019
    Posts
    5
    should be c

  10. #10
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    a couple of suggestions i....
    you don't need two input headers if its supposed to be c get rid of iostream,h
    second you need an array for the board with 64 individual numbers otherwise you wont be able to tell where the queen is i suggest 0 to 63 ie
    Code:
    int chessboard[8][8] = {0,1,2,3,4,5,6,7,
                            8,9,10,11,12,13,14,15,
                            16,17,18,19,20,21,22,23,
                            24,25,26,27,28,29,30,31,.......
                            ............60,61,62,63};
    that way you can tell what square your queen is on and your answer gives unique results. You can also easily see where the edges of the board are ifor example if your vertical co-ordinate is 3 to get all the squares up and down the board you jst have to get the results of chessboard[0][3] chessboard[1][3] ..... chessboard[8][3].

    coop

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,983
    I take it you actually know how a queen moves on a chess board.

    > The chessboard is presented as a matrix 8x8. Queen's position is entered from the keyboard into [word] [number]. And the result is saved in a string. "
    What does that "result as a string" actually mean?

    A chess board like this?
    Code:
    QXXXXXXX
    XX......
    X.X.....
    X..X....
    X...X...
    X....X..
    X.....X.
    X......X
    Or some list of coordinates like A1,A2,A3,A4,.....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple program for my school project. PLEASE HELP! :(
    By lmaea in forum C++ Programming
    Replies: 8
    Last Post: 03-19-2016, 04:03 AM
  2. C-program for school.
    By richv in forum C Programming
    Replies: 6
    Last Post: 09-15-2013, 02:45 PM
  3. My Program for School. Help?
    By Tommy Kim in forum C Programming
    Replies: 2
    Last Post: 04-20-2013, 02:56 PM
  4. help with a program for school
    By ssjnamek in forum C++ Programming
    Replies: 17
    Last Post: 01-14-2003, 08:26 PM

Tags for this Thread