Devc++ 编译问题,看不到运行结果

freeicy2007 2010-11-03 08:00:14
没有错误,但输入完一闪就没了,看不到结果,加了getchar还是不行,另外如果加getch会出现错误,不知道是哪不对,代码如下
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
const int MAX_ITEMS=8;
float x[MAX_ITEMS];
float average;
float sum;

cout << "Enter " << MAX_ITEMS << "numbers: ";
for( int i=0;i<MAX_ITEMS;i++)
cin >> x[i];

sum=0.0;
for( int i=0;i<MAX_ITEMS;i++){
sum+=x[i];
average = sum / MAX_ITEMS;

cout << " The average value is " << average << endl << endl << endl;

cout << " Table of differences between x[i] and the average." << endl;

cout << setw(4) << "next" << setw(8) << "x[next]"
<< setw(14) << "difference" << endl;
}
for(int i=0;i<MAX_ITEMS;i++){
cout << setw(4) << i << setw(8) << x[i]
<< setw(14) << (x[i]-average) << endl;
}
getch();
return 0;

}
...全文
811 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
無_1024 2010-11-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 freeicy2007 的回复:]
\C++\DEV C++\Dev-Cpp\practict\Untitled1.cpp D:\C++\DEV C++\Dev-Cpp\practict\D cconio: No such file or directory. 这文件似乎打不开
[/Quote]
不要用<cconio>因为他是C语言的 用<conio.h>
明月生寒 2010-11-04
  • 打赏
  • 举报
回复
#include <iostream>
#include <iomanip>
#include <conio.h>

using namespace std;

int main(){
const int MAX_ITEMS=8;
float x[MAX_ITEMS];
float average;
float sum;

cout << "Enter " << MAX_ITEMS << "numbers: ";
int i;
for(i=0;i<MAX_ITEMS;i++)
cin >> x[i];

sum=0.0;

for(i=0;i<MAX_ITEMS;i++){
sum+=x[i];
average = sum / MAX_ITEMS;

cout << " The average value is " << average << endl << endl << endl;

cout << " Table of differences between x[i] and the average." << endl;

cout << setw(4) << "next" << setw(8) << "x[next]"
<< setw(14) << "difference" << endl;
}
for(i=0;i<MAX_ITEMS;i++){
cout << setw(4) << i << setw(8) << x[i]
<< setw(14) << (x[i]-average) << endl;
}
getch();
return 0;

}
leemeng0x61 2010-11-04
  • 打赏
  • 举报
回复
system("pause");
或者cmd运行可执行文件
freeicy2007 2010-11-03
  • 打赏
  • 举报
回复
\C++\DEV C++\Dev-Cpp\practict\Untitled1.cpp D:\C++\DEV C++\Dev-Cpp\practict\D cconio: No such file or directory. 这文件似乎打不开
無_1024 2010-11-03
  • 打赏
  • 举报
回复
你还差一个头文件#include<conio.h> 是对应getch()的
或者用#include<stdlib.h>的system("pause");都可以
flower_fancy 2010-11-03
  • 打赏
  • 举报
回复
在return 0语句前添加system("pause");然后添加头文件#include<stdlib.h>,就可以了。。。

64,662

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧