被调函数输出话语没有在运行结果中显示出来
被调函数输出语句没有在运行结果中显示出来
#include "stdafx.h"
#include <iostream>
using namespace std;
int max(int x,int y)
{
float m;
cout<<"The initial x,y:"<<x<<","<<y<<endl;
m=x>y?x:y;
x=2*x;y=y+1;
cout<<"The new x,y:"<<x<<","<<y<<endl;
return(m);
}
void main()
{
float a,b,c;
cout<<"Please input two integer number:";
cin>>a>>b;
c=max(a,b);
cout<<"The maxinum is :"<<c<<endl;
cout<<"After calling function,a,b:"<<a<<","<<b<<endl;
system("pause");
}
1.问题:被调函数的输出语句运行时没有显示在窗口,为什么?
就是max()中的
The initial x,y:
The new x,y:
没有在运行结果中显示出来?
------解决方案--------------------
main:
float a,b,c;
...
c=max(a,b);
=================
int max(int x,int y)
float m;
...
return(m);
==============这类型让你转换的,
1.float的a,b传给int 的x,y
2.int 的x,y中之一又赋给float的m
3.float的m又按int返回
4.int的返回值又赋给float 的c
你还想让程序正确执行?
------解决方案--------------------
参数类型不一致!看看重载函数吧
------解决方案--------------------
应该开发环境的默认包含的库里面含有 更匹配的max函数吧
比如 int max( int , int)
------解决方案--------------------
------解决方案--------------------
没有改动楼主的代码,在VS2010也是有输出滴。
------解决方案--------------------
请忽视我前面的回答。
sorry,楼主应该将max改为Max,否则main函数中调用的是库中的max函数,而不是楼主自定义的那个max函数。
------解决方案--------------------
#include "stdafx.h"
#include <iostream>
using namespace std;
int max(int x,int y)
{
float m;
cout<<"The initial x,y:"<<x<<","<<y<<endl;
m=x>y?x:y;
x=2*x;y=y+1;
cout<<"The new x,y:"<<x<<","<<y<<endl;
return(m);
}
void main()
{
float a,b,c;
cout<<"Please input two integer number:";
cin>>a>>b;
c=max(a,b);
cout<<"The maxinum is :"<<c<<endl;
cout<<"After calling function,a,b:"<<a<<","<<b<<endl;
system("pause");
}
1.问题:被调函数的输出语句运行时没有显示在窗口,为什么?
就是max()中的
The initial x,y:
The new x,y:
没有在运行结果中显示出来?
------解决方案--------------------
main:
float a,b,c;
...
c=max(a,b);
=================
int max(int x,int y)
float m;
...
return(m);
==============这类型让你转换的,
1.float的a,b传给int 的x,y
2.int 的x,y中之一又赋给float的m
3.float的m又按int返回
4.int的返回值又赋给float 的c
你还想让程序正确执行?
------解决方案--------------------
参数类型不一致!看看重载函数吧
------解决方案--------------------
应该开发环境的默认包含的库里面含有 更匹配的max函数吧
比如 int max( int , int)
------解决方案--------------------
------解决方案--------------------
没有改动楼主的代码,在VS2010也是有输出滴。
------解决方案--------------------
请忽视我前面的回答。
sorry,楼主应该将max改为Max,否则main函数中调用的是库中的max函数,而不是楼主自定义的那个max函数。
------解决方案--------------------
- C/C++ code
#include <iostream> using namespace std; int Max(int x,int y) // 函数名不要和库函数名max相同,否则这个函数根本没有机会得到调用,自然也就木有输出了。 { float m; cout<<"The initial x,y:"<<x<<","<<y<<endl; m=x>y?x:y; x=2*x;y=y+1; cout<<"The new x,y:"<<x<<","<<y<<endl; return(m); } void main() { float a,b,c; cout<<"Please input two integer number:"; cin>>a>>b; c=Max(a,b); cout<<"The maxinum is :"<<c<<endl; cout<<"After calling function,a,b:"<<a<<","<<b<<endl; system("pause"); }
------解决方案--------------------
尽量把名字起得独特点,加个下划线