底片不能很好地叠加
Negatives not adding well
代码在这里
#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。
我看到了和你一样的东西:http://ideone.com/jaGeXx
1 + -4 = -317
是由代码中的两行创建的:
cout << ans1 << " + " << ans2 << " = " << ans3;
cout << result << "n";
第一个生成
第二个生成1 + -1 = -3
17
你没有要求任何分隔换行符或空格。所以你的程序很高兴地将它们并排发送到屏幕上。
-3 = -3
(-1)²+ 4²= 17
确保在-3到17之间打印一个换行符
相关文章:
- 我编写了代码将十进制分数转换为其二进制等效数.它编译得很好,但在执行时挂起
- 很好的语法来获取对向量/数组数据的大小引用?
- 我认为我的代码很好,但它在 cin a 之后停止并且没有进一步?
- 尽管一切看起来都很好,但值不会交换
- 为什么不同类型层次结构的指针之间的dynamic_cast定义得很好?
- 在 C++11 中利用 int*_t、int_fast*_t 和 int_least*_t 之间的差异的一个很好的例子是
- 对于短字符串来说,这是一个很好的哈希函数吗?
- 为什么指标有时效果很好,有时效果不佳?写下霍夫曼代码
- Red Hat:使用<atomic>编译很好,但链接器找不到__atomic_store_16;什么库?
- 使用移位的无符号数字作为数组的索引号是一种很好的做法
- 是否很好地使用状态模式来维护当前选定的对象?
- C++|以一种很好的方式将树(不一定是二进制的)打印到stdout
- 静态库单独使用很好,但在引用时会抛出错误
- 如果验证容器的大小并在同一条件语句下访问元素,这是很好的做法吗?
- 可变参数函数模板不能很好地使用 std::function 作为参数
- 有没有办法关闭文件? fclose 不能很好地工作
- 引用的静态强制转换强制模板实例化,其中不完整的类型很好
- libc++:为什么流关闭后仍然很好
- 不能很好地运行HElib,但它建立在Windows 10 x64上
- 底片不能很好地叠加