| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1039 人关注过本帖
标题:不懂错误在哪,找不出啊。。。
只看楼主 加入收藏
随风晨爱
Rank: 1
等 级:新手上路
帖 子:27
专家分:2
注 册:2017-6-1
结帖率:91.67%
收藏
已结贴  问题点数:20 回复次数:2 
不懂错误在哪,找不出啊。。。
#include <iostream>
using namespace std;
int main ()
{
    void sort(int x, int y, int z);
    int a,b,c;
    cin>>a>>b>>c;
    sort(a,b,c);
            return 0;
   
    }
    void sort(int x,int y,int z);
    {
        int temp;
        if(x>y) {temp=x;x=y;y=temp;}
        if(z<y) cout<<z<<","<<x<<","<<y<<endl;
        else if (z<y) cout<<x<<","<<z<<","<<y<<endl;
        else cout<<z<<","<<x<<","<<y<<endl;
    }
图片附件: 游客没有浏览图片的权限,请 登录注册
问题出在哪里呢。。。有错误
搜索更多相关主题的帖子: 错误 int sort temp cout 
2018-10-12 22:52
rohalloway
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:97
专家分:405
注 册:2018-9-28
收藏
得分:20 
你的代码有2处错误:
第一: void sort(int x, int y, int z);  //这里多了分号,改为 void sort(int x, int y, int z)

第二:你的sort函数声明在main函数下面,同时main函数前没有函数的原型声明,所以执行时main中的调用会找不到sort
解决办法是将sort函数的实现放在main之前,
或者在main前面加上sort的函数定义,推荐这种方式。

程序代码:
#include <iostream>
using namespace std;

void sort(int x, int y, int z); //sort函数的定义

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    sort(a, b, c);
    system("pause");
    return 0;

}
void sort(int x, int y, int z)   //sort函数的实现
{
    int temp;
    if (x>y) { temp = x; x = y; y = temp; }
    if (z<y) cout << z << "," << x << "," << y << endl;
    else if (z<y) cout << x << "," << z << "," << y << endl;
    else cout << z << "," << x << "," << y << endl;
}


[此贴子已经被作者于2018-10-13 00:16编辑过]

2018-10-13 00:12
随风晨爱
Rank: 1
等 级:新手上路
帖 子:27
专家分:2
注 册:2017-6-1
收藏
得分:0 
回复 2楼 rohalloway
好了,谢谢
2018-10-13 14:03
快速回复:不懂错误在哪,找不出啊。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016466 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved