| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 702 人关注过本帖
标题:求助高手帮我看看!程序运行不对!
只看楼主 加入收藏
wangyidj05
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-3-24
收藏
 问题点数:0 回复次数:2 
求助高手帮我看看!程序运行不对!
--------------------Configuration: PROG - Win32 Debug--------------------
Compiling...
PROG.C
c:\wexam\00000000\prog.c(21) : error C2065: 'totcnt' : undeclared identifier
c:\wexam\00000000\prog.c(22) : error C2065: 'totpjz' : undeclared identifier
Error executing cl.exe.

PROG.exe - 2 error(s), 0 warning(s)
----------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#define MAXNUM 200
int xx[MAXNUM] ;
int totNum = 0 ;
int totCnt = 0 ;
double totPjz = 0.0 ;
int ReadDat(void) ;
void Writedat(void) ;
void CalValue(void)
{
    int i,j;
    int data;
    for(i=0;i<MAXNUM;i++)
        if(xx[i]>0);
        {
            totNum++;
            data=xx[i]>>1;
            if(data%2!=0)
            {
                totcnt++;
                totpjz+=xx[i];
            }
        }
                totpjz/=totcnt;
 }
void main()
{
 int i ;
 system("CLS");
 for(i = 0 ; i < MAXNUM ; i++)
    xx[i] = 0 ;
 if (ReadDat ())
    {
     printf("数据文件IN11.DAT不能打开!\007\n");
     return ;
    }
 CalValue() ;
 printf("文件IN11.DAT中共有正整数= %d 个\n", totNum);
 printf("符合条件的正整数的个数= %d 个\n", totCnt);
 printf("平均值=%.2lf\n", totPjz);
 Writedat() ;
}
int ReadDat(void)
{
 FILE *fp;
 int i = 0 ;
 if((fp = fopen ("IN11.DAT", "r")) == NULL)
    return 1 ;
 while(! feof(fp))
    {
     fscanf(fp, "%d,", &xx[i++]) ;
    }
 fclose(fp) ;
 return 0 ;
}
void Writedat(void)
{
 FILE *fp;
 fp = fopen("OUT11.DAT", "w") ;
 fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
 fclose(fp) ;
}
---------------------------------------------------------------------------------------------------------
运行结果
文件IN11.DAT中共有正整数=0个
符合条件的正整数的个数=0个
平均值=0.00
perss any key to contine
搜索更多相关主题的帖子: PROG identifier 
2008-04-02 16:24
now
Rank: 1
来 自:广州
等 级:新手上路
帖 子:544
专家分:0
注 册:2007-11-9
收藏
得分:0 
程序代码:
#include <stdio.h>
#include <stdlib.h>
#define MAXNUM 200
int xx[MAXNUM] ;
int totNum = 0 ; 
int totCnt = 0 ; 
double totPjz = 0.0 ; 
int ReadDat(void) ;
void Writedat(void) ;
void CalValue(void)
{
    int i,j;
    int data;
    for(i=0;i<MAXNUM;i++)
        if(xx[i]>0);
        {
            totNum++;
            data=xx[i]>>1;
            if(data%2!=0)
            {
                totCnt++;       //这里C为大写,下同;
                totPjz+=xx[i];
            }
        }
                totPjz/=totCnt;
}
void main()
{
int i ;
system("CLS");
for(i = 0 ; i < MAXNUM ; i++) 
    xx[i] = 0 ;
if (ReadDat ()) 
    {
     printf("数据文件IN11.DAT不能打开!\007\n");
     return ;
    }
CalValue() ;
printf("文件IN11.DAT中共有正整数= %d 个\n", totNum);
printf("符合条件的正整数的个数= %d 个\n", totCnt);
printf("平均值=%.2lf\n", totPjz);
Writedat() ;
}
int ReadDat(void)
{
FILE *fp;
int i = 0 ;
if((fp = fopen ("IN11.DAT", "r")) == NULL) 
    return 1 ;
while(! feof(fp)) 
    {
     fscanf(fp, "%d,", &xx[i++]) ;
    }
fclose(fp) ;
return 0 ;
}
void Writedat(void)
{
FILE *fp;
fp = fopen("OUT11.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

注意下大小写;应该可以了。

[[it] 本帖最后由 now 于 2008-4-2 19:20 编辑 [/it]]

GIS
Geographic Information System
你在哪里?——》你的坐标?
2008-04-02 19:17
wangyidj05
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-3-24
收藏
得分:0 
哈哈  弄好拉  谢谢啦
2008-04-02 22:25
快速回复:求助高手帮我看看!程序运行不对!
数据加载中...
 
   



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

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