Question

In: Computer Science

c++ I am getting errors that say "expected a declaration". can you explain what it means...

c++ I am getting errors that say "expected a declaration". can you explain what it means by this and how I need to fix it?  

#include <iostream>
using namespace std;

//functions
void setToZero(int board[8][8]);
void displayBoard(int oboard[8][8]);
void movingFunction();

int main()
{
   // chess board 8x8
   int board[8][8];

   // all of the possible moves of the knight in 2 arrays
   int colMove[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
   int rowMove[8] = { -1, -2, -2, -1, 1, 2, 2, 1 };

   int row = 0; // starting row
   int col = 0; // starting column
   int newRow = 0; // transition row
   int newCol = 0; // transition column
   int mover = 1; // position # / tracker increase by 1 everytime a new position is found

   // function to set values to 0
   setToZero(board);

   board[row][col] = 1; // starting position in top left set to one

   bool ableToMove = true; // set to true so that while loop always executes

   // function to decide where knight will move
   movingFunction();

   // function to display board
   displayBoard(board);

   cin.get();
   cin.get();
   return 0;

}

//function to initialize to zero
   void setToZero(int fboard[8][8])
{
   for (int i = 0; i < 8; i++)
       for (int j = 0; j < 8; j++)
           fboard[i][j] = 0;
}

//function to display the board
void displayBoard(int oboard[8][8])
{
   int i, j;
   for (i = 0; i < 8; i++)
   {
       for (j = 0; j < 8; j++)
       {
           cout << " " << oboard[i][j] << " ";
       }
       cout << " " << endl;

   }

}

// function that enables knight to move
void movingFunction();
{
   while (ableToMove)
   {
       ableToMove = false;

       for (int i = 0; i < 8; i++)
       {
           for (int j = 0; j < 8; j++)
           {
               newRow = row + rowMove[i];
               newCol = col + colMove[j];

               // ensures that knight is staying on the board
               if (newRow >= 0 && newRow < 8 && newCol >= 0 && newCol < 8 && board[newRow][newCol] == 0)
               {
                   ableToMove = true; // becomes true if able to move
                   break;
               }
           }
           if (ableToMove == true)
           {
               break;
           }
       }
       if (ableToMove) // if became true, values are changed and "mover" (knight) increases

       {
           row = newRow;
           col = newCol;
           board[row][col] = ++mover;

       }
   }

}

Solutions

Expert Solution

#include <iostream>

using namespace std;

//functions
void setToZero(int board[8][8]);

void displayBoard(int oboard[8][8]);

void movingFunction(int board[8][8], int rowMove[8], int colMove[8]);

int main() {
    // chess board 8x8
    int board[8][8];

    // all of the possible moves of the knight in 2 arrays
    int colMove[8] = {2, 1, -1, -2, -2, -1, 1, 2};
    int rowMove[8] = {-1, -2, -2, -1, 1, 2, 2, 1};

    int row = 0; // starting row
    int col = 0; // starting column
    int newRow = 0; // transition row
    int newCol = 0; // transition column
    int mover = 1; // position # / tracker increase by 1 everytime a new position is found

    // function to set values to 0
    setToZero(board);

    board[row][col] = 1; // starting position in top left set to one

    bool ableToMove = true; // set to true so that while loop always executes

    // function to decide where knight will move
    movingFunction(board, rowMove, colMove);

    // function to display board
    displayBoard(board);

    cin.get();
    cin.get();
    return 0;

}

//function to initialize to zero
void setToZero(int fboard[8][8]) {
    for (int i = 0; i < 8; i++)
        for (int j = 0; j < 8; j++)
            fboard[i][j] = 0;
}

//function to display the board
void displayBoard(int oboard[8][8]) {
    int i, j;
    for (i = 0; i < 8; i++) {
        for (j = 0; j < 8; j++) {
            cout << " " << oboard[i][j] << " ";
        }
        cout << " " << endl;

    }

}

// function that enables knight to move
void movingFunction(int board[8][8], int rowMove[8], int colMove[8]) {
    int row = 0; // starting row
    int col = 0; // starting column
    int newRow = 0; // transition row
    int newCol = 0; // transition column
    int mover = 1; // position # / tracker increase by 1 everytime a new position is found
    bool ableToMove = true;
    while (ableToMove) {
        ableToMove = false;

        for (int i = 0;i < 8; i++) {
            for (
                    int j = 0;
                    j < 8; j++) {
                newRow = row + rowMove[i];
                newCol = col + colMove[j];

// ensures that knight is staying on the board
                if (newRow >= 0 && newRow < 8 && newCol >= 0 && newCol < 8 && board[newRow][newCol] == 0) {
                    ableToMove = true; // becomes true if able to move
                    break;
                }
            }
            if (ableToMove == true) {
                break;
            }
        }
        if (ableToMove) // if became true, values are changed and "mover" (knight) increases
        {
            row = newRow;
            col = newCol;
            board[row][col] = ++mover;
        }
    }
}

Related Solutions

I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
Can someone please tell me why I am getting errors. I declared the map and it's...
Can someone please tell me why I am getting errors. I declared the map and it's values like instructed but it's telling me I'm wrong. #include <iostream> #include <stdio.h> #include <time.h> #include <chrono> #include <string> #include <cctype> #include <set> #include <map> #include "d_state.h" using namespace std; int main() { string name; map<string,string> s; map<string,string>::iterator it; s[“Maryland”] = "Salisbury"; s[“Arizona”] = "Phoenix"; s[“Florida”] = "Orlando"; s[“Califonia”] = "Sacramento"; s[“Virginia”] = "Richmond"; cout << "Enter a state:" << endl; cin >> name;...
I working on this program in C++ and I keep getting 20 errors of the same...
I working on this program in C++ and I keep getting 20 errors of the same type again.cpp:36:11: error: use of undeclared identifier 'Polynomial' int main() { // create a list of polinomials vector<Polynomial> polynomials; // welcome message cout << "Welcome to Polynomial Calculator" << endl; int option = 0; while (option != 6) { // display menu displayMenu(); // get user input; cin >> option; if (option == 1) { cout << "Enter a polynomial :" << endl; string...
Develop the following code for quiz (i am getting some errors)in python in such a manner...
Develop the following code for quiz (i am getting some errors)in python in such a manner that it shoulde be having extra 3 attempts(for wrong answrs) for all questions if the user entered wrong answer · for ex: If the user entered correct answer for first question #then 3 attempts will be carried to next questions. If the user entered 3 times wrong answer in 1st question itself means it sholud display as no more attempts and you got o...
I am having trouble with my assignment and getting compile errors on the following code. The...
I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments. /* Chapter 5, Exercise 2 -Write a class "Plumbers" that handles emergency plumbing calls. -The company handles natural floods and burst pipes. -If the customer selects a flood, the program must prompt the user to determine the amount of damage for pricing. -Flood charging is based on the numbers of damaged rooms. 1 room costs $300.00, 2 rooms...
Syntax error in C. I am not familiar with C at all and I keep getting...
Syntax error in C. I am not familiar with C at all and I keep getting this one error "c error expected identifier or '(' before } token" Please show me where I made the error. The error is said to be on the very last line, so the very last bracket #include #include #include #include   int main(int argc, char*_argv[]) {     int input;     if (argc < 2)     {         input = promptUserInput();     }     else     {         input = (int)strtol(_argv[1],NULL, 10);     }     printResult(input);...
Can anyone explain to me why I am getting an access violation when I try to...
Can anyone explain to me why I am getting an access violation when I try to add notes? It occurs when I try to set the "pLast" pointer to the previous node (for a doubly linked list). The code worked as singly linked list. When I added a "pLast" pointer and the needed code to make it a doubly linked list everything broke. #include <iostream> #include <stdlib.h> using namespace std; //build class that has a private function to inc count....
Can someone explain in detail how to solve the below indefinite integral? I am getting really...
Can someone explain in detail how to solve the below indefinite integral? I am getting really confused when it comes to the U-substitution part and do not understand how 9 ends up in the denominator. I know the correct answer is [-2(ln3x+1)-3x]/9 + C, but I do not know how to get there. ∫(2x)/(3x+1) dx
I kept getting errors trying to make this code to work, can someone show me what...
I kept getting errors trying to make this code to work, can someone show me what i am doing wrong? import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.annotation.*; import java.io.*; import java.util.*; import java.nio.file.*; import java.nio.charset.*; import java.util.*; //@WebServlet(name = "Assignment3_1", urlPatterns = { "/ReadFile" }) public class ReadFile extends HttpServlet{ static Charset myCharset = Charset.forName("US-ASCII"); @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ response.setContentType("text/html"); PrintWriter printer = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>"); out.println("Assignment 5.1"); out.println("</title>"); out.println("<h1>Is Bitcoin money?</h1>"); out.println("</head>"); out.println("<body>");...
Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell...
Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell that says payment is undefined. I am trying to create a main.js file that imports the function from the hr.js file; call the function passing the necessary arguments and log the result to the console. main.js var Dev = require("./hr.js") const { add } = require("./hr.js") var dev_type = 1; var hr = 40; console.log("your weekly payment is " + payment(dev_type, hr)) dev_type =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT