Condition of the problem: Given the coordinates (as integers from 1 to 8) of two chessboard fields. Check if the knight can move from one field to another in one move. Create a program that uses the function to perform the check. The function should return the value 1 (true) or 0 (false). Ps That is, enter the coordinates where the horse stood, and the coordinates where to move it, if it is according to the rules then return 1 if not then zero.
Waiting for any advice and criticism.
#include "pch.h" #include <iostream> #include "windows.h" #include "iostream" #include "math.h" using namespace std; int ProverkaPravilnostiDanuh(int i1, int j1, int i2, int j2, int r1, int r2) {} int main() { int Starti, Finishi, Startj, Finishj, r1, r2, c; cout << "Vvedite Kordinatu start i Finish " << endl; cin >> Starti >> Startj; cout << endl; cin >> Finishi >> Finishj; cout << endl; c = ProverkaPravilnostiDanuh(Starti, Startj, Finishi, Finishj, r1,r2); if (c == 0 || 1) cout << "Eto vozmojno"; else cout << "Ne vernue kordnatu"; system("pause"); return 0; } int ProverkaPravilnostiDanuh(int i1, int j1, int i2, int j2, int r1, int r2){ r1 = i2 - i1; r2 = j2 - j1; if (abs(r1) == 1 && abs(r2) == 2) return 1; else if (abs(r2) == 1 && abs(r1) == 2) return 1; else; return 0; }
ProverkaPravilnostiDanuh
, you have two definitions. - ⷶ ⷩ ⷮ ⷪ ⷩ