| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 290 人关注过本帖
标题:找问题 逻辑错误 不过只找find1(int cj)和case3的 求助!!
只看楼主 加入收藏
yxy1995523
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2012-11-15
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:2 
找问题 逻辑错误 不过只找find1(int cj)和case3的 求助!!
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>

#define  NUM  30
int    student[NUM];            //数组个数最大30
int    n=0;                    //记录元素的实际个数,也是最大的顺序号
int flag=0;                    //记录是否已建立过成绩数组,flag=0,为未建立过成绩数组;
                            //若已建立,则不能再次建立成绩数组,               
int find1(int x);
int fing2(int x);//被调用函数集中声明;         如:int  create();



//程序主入口
void main(void)
{   
    int menuchoice;
    int cj,sxh,i;                    //输入成绩和顺序号变量;
    int j,a[30],min,temp;
   
    FILE *fp;
    fp=fopen("c:\\a.txt","r");
    system("color f0");   
    /*设置默认的控制台前景和背景颜色。
                                    COLOR [attr],attr指定控制台输出的颜色属性。
                                        颜色属性由两个十六进制数字指定。第一个为背景,第二个为前景。
                                        0=黑色 1=蓝色 2=绿色 3=湖蓝色 4=红色 5=紫色 6=黄色 7=白色
                                        8=灰色 9=淡蓝色 a=淡绿色 b=淡浅绿色 c=淡红色 d=淡紫色 e=淡黄色 f=亮白色*/
   
    do{        
        system("cls");                           
        printf("\n\n\n\n");
        printf("\t\t\t数组基本功能菜单        \n");
        printf("\t\t\t  作者:* * *            \n");
        printf("\t\t\t  ============        \n");
        printf("\t\t\t  1.建立成绩数组        \n");
        printf("\t\t\t  2.显示成绩数组        \n");
        printf("\t\t\t  3.按给定成绩查找    \n");
        printf("\t\t\t  4.按顺序号查找        \n");
        printf("\t\t\t  5.从高到低排序输出    \n");
        printf("\t\t\t  6.从低到高排序输出    \n");
        printf("\t\t\t  7.给定顺序号插入成绩\n");
        printf("\t\t\t  8.给定顺序号删除成绩\n");
        printf("\t\t\t  9.给定顺序号修改成绩\n");
        printf("\t\t\t  10.结束程序            \n");
        printf("\t\t\t  ============        \n");
   
        
            
        printf("\t\t\t请输入您的选择:        \n");   
   
   
        scanf("%d",&menuchoice);
        

        switch(menuchoice)   //根据用户的选择进行相应的操作
        {
        case 1:
            
                if(flag==0)
                {
               
                printf("请输入实际人数");
                scanf("%d",&n);
            for(i=0;i<n;i++)
            {
                fscanf(fp,"%d",&student[i]);
                printf("%d..\t",student[i]);
            }
        fclose(fp);
                }
               
                system("pause");
                if(flag==1)
                {
                    
                    printf("您的输入有误,按任意键继续···");
                    system("pause");
                }
                flag=1;
                    break;
   
            case 2:
                    for(i=0;i<=n;i++)
               
                    printf("成绩为%d",student[i]);
                    system("pause");        
                    break;
            case 3:
               
                    find2(cj);
                    system("pause");        
                    break;
   
            case 4:
                    printf("请输入顺序号");
                    scanf("%d",&sxh);
                    if(sxh<0&&sxh>30)
                        printf("error");
                    do{
                        
                        find1(sxh);
                        
                    }while(sxh>0&&sxh<30);
                    system("pause");   
                    break;
            
            case 5:
               
            
            for(i=0;i<n;i++)

            a[i]=student[i];
            for(i=0;i<n-1;i++)
            {

            min=i;
            for(j=i+1;j<n;j++)
            if(a[min]<a[j])
            min=j;
            }
            if(min!=i)
            {
            temp=a[i];
            a[i]=a[min];
            a[min]=temp;
            }
            for(i=0;i<n;i++)
            printf("%d\t",a[i]);
            
               
                    system("pause");        
                    break;

            case 6:

                    
                    for(i=0;i<n;i++)

                    scanf("%d",&a[i]);
                    for(i=0;i<n-1;i++)
                    {

                    min=i;
                for(j=i+1;j<n;j++)
                if(a[min]<a[j])
                min=j;
                    }
                if(min!=i)
                {
                temp=a[i];
                a[i]=a[min];
                a[min]=temp;
                }
                for(i=n;i>0;i--)
                printf("%d\t",a[i]);
            
                    system("pause");        
                    break;
                           
            case 7:
               
                    printf("请输入要插入之前的顺序号");
                    scanf("%d",&sxh);
                    if(sxh<0&&sxh>30)
                        printf("error");
                    do{
                    
                    printf("请输入要插入的成绩");
                    scanf("%d",&cj);
                    
                    for(i=0,j=0;student[i]!='\0';i++)
                        if(student[i]!=sxh)
                            student[j]=student[i++];
                            for(i=0;i<=n+1;i++)
                            printf("%d",student[i]);
                    }while(sxh>0&&sxh<30);
                    break;
                    
            case 8:
                    printf("请输入要删除的顺序号");
                    scanf("%d",&sxh);
               
                    for(i=0,j=0;i!='0';i++)
                        if(a[i]!=sxh);
                        student[j++]=student[i];
                        student[j]='\0';
                        for(i=0;i<=n-1;i++)
                            printf("%d",student[i]);
                    system("pause");        
                    break;
            case 9:
               
                printf("请输入顺序号以便修改");
                scanf("%d",&sxh);
                if(sxh>30)
                    printf("error");
                    system("pause");
                    break;
                    if(sxh>0&&sxh<30)
                        printf("请输入要修改的成绩");
                    scanf("%d",&cj);
                    student[sxh]=cj;
                    for(i=0;i<=n;i++)
                    printf("%d",student[i]);
                    
                    break;
            
            case 10:     
                    printf("\n欢迎使用本成绩管理系统,再见!\n");
                    system("pause");  
                    exit(0);
            
            default:
                    printf("\n对不起,您输入的功能编号有错!请重新输入!!!\n");
                    system("pause");
                    break;
    }
    }while(1);
   
    }



//以下为各功能函数
int find2(int cj)
{
    int i;
    printf("请输入成绩");
    scanf("%d",&cj);
    for(i=0;i<=n;i++)
   
    {
        if(student[i]=cj)
        printf("%d\t",i+1);
        if(student[i]!=cj)
        printf("error");

    }
   
}

int find1(int sxh)
{
        int i;
        printf("请输入顺序号");
        scanf("%d",&sxh);
        for(i=0;i<=n;i++)
        {
            if(i==sxh)
            printf("%d",student[sxh]);
        if(i!=sxh)
            printf("\terror");
}
}

搜索更多相关主题的帖子: void 记录 include create 最大的 
2012-12-12 21:02
yxy1995523
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2012-11-15
收藏
得分:0 
find2的  搞错了
2012-12-12 21:03
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:20 
int find2(int cj)
{
    int i;
    printf("请输入成绩");
    scanf("%d",&cj);
楼主这里是不是错了,传过来的cj被破坏了啊

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2012-12-13 20:58
快速回复:找问题 逻辑错误 不过只找find1(int cj)和case3的 求助!!
数据加载中...
 
   



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

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