首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

为什么调用不了函数解决思路

2012-02-19 
为什么调用不了函数程序简单:#include iostream.htypedefunsignedshortintushortintk(ushorti,ushortj)

为什么调用不了函数
程序简单:
#include <iostream.h>
typedef   unsigned   short   int   ushort;

int   k(ushort   i,ushort   j)
{

return   i/j;
}
void   main()
{
ushort   i   ,j;
cout < < "enter   two   number: " < <endl;
cout < < "number   one: ";
cin> > i;
cout < < "number   two: ";
cin> > j;

  k(i,   j);

cout < < "answer: " < <k < <endl;
}

我试过debug了,程序居然没有调用k;
我用了别的程序以同样的方法编,如下:
#include <iostream.h>
long   fib(int   n)

{
long   s;
if(n==1||n==2)
return   1;
s=fib(n-1)+fib(n-2);
return   s;
}
void   main()
{
int   n;

cout < < "请输入一个整数: ";
cin> > n;
fib(n);
cout < <fib(n) < <endl;


}

结果能调用fib,为什么啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[解决办法]
cout < < "answer: " < <k < <endl;//k是地址,改成如下没问题:

int ret;
ushort i ,j;
cout < < "enter two number: " < <endl;
cout < < "number one: ";
cin> > i;
cout < < "number two: ";
cin> > j;

ret=k(i, j);

cout < < "answer: " < <ret < <endl;
[解决办法]
//k(i,j);
cout < < "answer: " < <k(i,j) < <endl;

热点排行