问个我自己写的C++问题...

来源:百度知道 编辑:UC知道 时间:2024/06/25 11:22:08
#include<iostream>
int main()
{
using namespace std;
int ablea, ableb;
cout<<"what is the ablea"<<ablea;
cin>>ablea;
cout<<"then ableb=="<<ableb;
cin>>ableb;
if
(ablea==ableb)

cout<<"there are same";
else
cout<<"there are differece";

char response;
cin>>response;
return 0;
}

这个是我写的程序....新手....
不过运行后有个问题....
显示的是
what is the ablea 2//(然后我输入数字)
then ableb==50//(接着我输入数字)
其他没问题,就是那个2和50是什么意思?为什么会出现那个东西?
原来如此..我知道了....只能把答案给最好的一个....

你看,你cout之后跟了个ablea ableb吧?就是输出他们啊。他们可没有赋值,那就是随机数值了。2 和50就是这么来的了,只是凑巧。你换台机就不一定是这个数值了。

int ablea, ableb在定义的时候没有初始化,那么你用cout函数的时候输出的是一个系统随机值,在你的机器上每一次啊的结果是不一样的,要想解决这个问题,就在int ablea, ableb; 句中给他们初始化

在int ablea, ableb; 句中给他们初始化都为零就应该没什么问题的了

分别去掉地六行和第八行的<<ablea和<<ableb