关于c++输出的问题

来源:百度知道 编辑:UC知道 时间:2024/07/03 04:01:46
#include <iostream.h>
#include <conio.h>
int Abs(int a,int b);
int main()
{int a,b,c;
cout << "enter two number:" << endl;
cin >> a >> b;
c=Abs(a,b);
cout << c;
getchar();
return 0;
}
int Abs(int a ,int b)
{if(a>b)
return a;
return b;
}
这个程序我运行以后输入两个数载按下回车 运行界面就跳出来了那我怎么看运行结果啊

用getchar()的话会把回车当数据读进去的……

所以应该用cin之类的函数随便读入一个数据,正如楼上所说。

int main()
{int a,b,c,D;
cout << "enter two number:" << endl;
cin >> a >> b;
c=Abs(a,b);
cout << c;
getchar();
cin >> D;//let console stop here to wait u type a new number so that u can //see ur result
return 0;
}

应该把a,b声明成在前面为全局变量,因为在主函数和定义的函数中都用了相同的变量 了,getchar()将回车作为按任意键退出了,去掉就可以 了。

getchar()换为system("pause")