的代碼是在這裏否定不增加以及
#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 )它會帶出錯誤的答案,而不是我在紙上解決它時,我繼續按順序完成了步驟,並且它說1 + -4是-317,我很困惑,因爲這遠不是這樣。正確的答案,當然。那麼,什麼是錯了嗎?當我刪除從一開始就整數簽署它不會打破。
我使用的Visual Studio Express的2012,運行Windows 8
請不要吝嗇,這是一個簡單的意外。我的意思是Visual Studio 2012.我也使用C++控制檯應用程序。 – McBroColi 2013-05-02 00:09:12
隨意使用該「編輯」鏈接來解決您的問題。 – 2013-05-02 00:09:53
爲什麼這麼消極? – 2013-05-02 01:37:28