我用Dev C++ 编了一个程序,可是最后点一下回车就消失了
我用DevC++编了一个程序,是一个简单的乘法.具体的程序如下#include<iostream>usingnamespacestd;intmain(){intnumbe...
我用Dev C++ 编了一个程序,是一个简单的乘法.具体的程序如下
#include <iostream>
using namespace std;
int main()
{
int number_of_pods, peas_per_pod, total_peas;
cout << "Press return after entering a number.\n";
cout << "Enter the number of pods:\n";
cin >> number_of_pods;
cout << "Enter the number of peas in a pod:\n";
cin >> peas_per_pod;
total_peas = number_of_pods * peas_per_pod;
cout << "If you have ";
cout << number_of_pods;
cout << " pea pods\n";
cout << "and ";
cout << peas_per_pod;
cout << " peas in each pod, then\n";
cout << "you have ";
cout << total_peas;
cout << " peas in all the pods.\n";
return 0;
}
我编译(compile)了之后.一切正常,然后按运行(run),出来一个框,这时候应该是打2个数字进去,比如第一个数字打10,然后按回车,再打第二个数字9,再按回车,应该出来一个结果是90, 可是当我打完第二个数字,再按回车这个框就消失了,更别说显示结果了...望各位大哥大姐帮帮忙啊....就这一个错误弄了2小时了,头都大了..谢谢啊..刚注册的百度帐号,只有25分,只能给20分了..... 展开
#include <iostream>
using namespace std;
int main()
{
int number_of_pods, peas_per_pod, total_peas;
cout << "Press return after entering a number.\n";
cout << "Enter the number of pods:\n";
cin >> number_of_pods;
cout << "Enter the number of peas in a pod:\n";
cin >> peas_per_pod;
total_peas = number_of_pods * peas_per_pod;
cout << "If you have ";
cout << number_of_pods;
cout << " pea pods\n";
cout << "and ";
cout << peas_per_pod;
cout << " peas in each pod, then\n";
cout << "you have ";
cout << total_peas;
cout << " peas in all the pods.\n";
return 0;
}
我编译(compile)了之后.一切正常,然后按运行(run),出来一个框,这时候应该是打2个数字进去,比如第一个数字打10,然后按回车,再打第二个数字9,再按回车,应该出来一个结果是90, 可是当我打完第二个数字,再按回车这个框就消失了,更别说显示结果了...望各位大哥大姐帮帮忙啊....就这一个错误弄了2小时了,头都大了..谢谢啊..刚注册的百度帐号,只有25分,只能给20分了..... 展开
5个回答
2009-03-02
展开全部
两个方法:
方法1.加system("pause"); (相关头文件"stdlib.h")
方法2.加getch(); (相关头文件"conio.h")
改后的代码:
方法1.
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
int number_of_pods, peas_per_pod, total_peas;
cout << "Press return after entering a number.\n";
cout << "Enter the number of pods:\n";
cin >> number_of_pods;
cout << "Enter the number of peas in a pod:\n";
cin >> peas_per_pod;
total_peas = number_of_pods * peas_per_pod;
cout << "If you have ";
cout << number_of_pods;
cout << " pea pods\n";
cout << "and ";
cout << peas_per_pod;
cout << " peas in each pod, then\n";
cout << "you have ";
cout << total_peas;
cout << " peas in all the pods.\n";
system("pause");
return 0;
}
方法2.
#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
int number_of_pods, peas_per_pod, total_peas;
cout << "Press return after entering a number.\n";
cout << "Enter the number of pods:\n";
cin >> number_of_pods;
cout << "Enter the number of peas in a pod:\n";
cin >> peas_per_pod;
total_peas = number_of_pods * peas_per_pod;
cout << "If you have ";
cout << number_of_pods;
cout << " pea pods\n";
cout << "and ";
cout << peas_per_pod;
cout << " peas in each pod, then\n";
cout << "you have ";
cout << total_peas;
cout << " peas in all the pods.\n";
getch();
return 0;
}
方法1.加system("pause"); (相关头文件"stdlib.h")
方法2.加getch(); (相关头文件"conio.h")
改后的代码:
方法1.
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
int number_of_pods, peas_per_pod, total_peas;
cout << "Press return after entering a number.\n";
cout << "Enter the number of pods:\n";
cin >> number_of_pods;
cout << "Enter the number of peas in a pod:\n";
cin >> peas_per_pod;
total_peas = number_of_pods * peas_per_pod;
cout << "If you have ";
cout << number_of_pods;
cout << " pea pods\n";
cout << "and ";
cout << peas_per_pod;
cout << " peas in each pod, then\n";
cout << "you have ";
cout << total_peas;
cout << " peas in all the pods.\n";
system("pause");
return 0;
}
方法2.
#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
int number_of_pods, peas_per_pod, total_peas;
cout << "Press return after entering a number.\n";
cout << "Enter the number of pods:\n";
cin >> number_of_pods;
cout << "Enter the number of peas in a pod:\n";
cin >> peas_per_pod;
total_peas = number_of_pods * peas_per_pod;
cout << "If you have ";
cout << number_of_pods;
cout << " pea pods\n";
cout << "and ";
cout << peas_per_pod;
cout << " peas in each pod, then\n";
cout << "you have ";
cout << total_peas;
cout << " peas in all the pods.\n";
getch();
return 0;
}
展开全部
那不是错误,你可以在主函数的最好加一句
system("pause");
再代码的最前面加上
#include <cstdlib>
这样就可以了
system("pause");
再代码的最前面加上
#include <cstdlib>
这样就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
也可以加
getchar();
getchar();
於最后
getchar();
getchar();
於最后
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的程序输出结果后就直接return了,所以你看不到结果,你应该在程序输出结果之后让程序暂停,等你按键之后再接着往下执行,可以这么做:
system("pause"); /* 先include<windows.h> */
或者
getch(); /* 先include<conio.h> */
system("pause"); /* 先include<windows.h> */
或者
getch(); /* 先include<conio.h> */
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询