コードはこちら
#include "stdafx.h"
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main ()
{
cout << 1 + -4 << "\n";
signed int x1; //(x1, ...
signed int y1; //(x1, y1)...
signed int x2; //... (x2, ...
signed int y2; // ... (x2, y2)
signed int ans1;
signed int ans2;
signed int ans3;
signed int result;
cout << "X1: ";
cin >> x1;
cout << "\nY1: ";
cin >> y1;
cout << "\nX2: ";
cin >> x2;
cout << "\nY2: ";
cin >> y2;
cout << "\n(" << x1 << ", " << y1 << "), (" << x2 << ", " << y2 << ")\n";
result = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
cout << "X2 - X1 = " << x2 - x1 << "\n";
cout << "Y2 - Y1 = " << y2 - y1 << "\n";
ans1 = x2 - x1;
ans2 = y2 - y1;
ans3 = ans1 + ans2;
cout << ans1 << " + " << ans2 << " = " << ans3;
cout << result << "\n";
return 0;
}
単純な方程式のソルバーを作成しようとしています。簡単に言えば、(x2 - x1)(二乗) + (y2 - y1)(二乗) - これらは異なる数値であるため、座標を考えてください。(4, 3), (6, 2)
問題は、例として、8, 6, 9, 2 ((8, 6), (9, 2) と入力すると、紙で解くよりも間違った答えが出てくることです。私は先に進み、それを cout << 順番に並べると、1 + -4 は -317 であると書かれています. もちろん、これは正しい答えにはほど遠いので、私は非常に混乱しています. では、何が間違っているのでしょうか? それは壊れます最初の整数から署名を削除したとき。
Windows 8 を実行している Visual Studio Express 2012 を使用しています。