程序在结束时退出
Program exits at the end
我现在正在学习C++,非常新。我正在尝试制作一个非常简单的程序,它显示乘法表,当程序运行时,用户输入第一个数字,然后输入第二个数字,程序显示该表。但问题是,当我按下键盘上的任何键时,程序都会退出。我希望在这一点上,程序会重复它自己,并要求用户输入第一个数字。我的代码在这里:
#include <iostream>
#include <conio.h>
using namespace std;
int main(int argc,char**argv){
int value1;
int limit;
int result1=1;
int result2;
bool runing=false;
printf("Welcome n");
cout << "Please enter 1st value: " << flush;
cin >> value1;
cout << "Please enter a limit value: "<< flush;
cin >> limit;
cout<< "Result is: n";
while(result1<=limit){
result2=result1*value1;
printf("%d x %d = %dn",value1,result1,result2);
result1++;
}
return 0;
}
要想做什么,只需要另一个while循环,在打印欢迎之后包装所有内容。像这样:
#include <iostream>
#include <conio.h>
using namespace std;
int main(int argc,char**argv){
int value1;
int limit;
int result2;
bool runing=false;
printf("Welcome n");
//I don't know in which conditions you want to quit the program.
//You could also use for() instead, to run this piece of code a certain number of times.
while(true){
int result1=1;
cout << "Please enter 1st value: " << flush;
cin >> value1;
cout << "Please enter a limit value: "<< flush;
cin >> limit;
cout<< "Result is: n";
while(result1<=limit){
result2=result1*value1;
printf("%d x %d = %dn",value1,result1,result2);
result1++;
}
}
return 0;
}
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 为什么在这个代码结束循环中没有得到结束
- 创建LinkedList退出,返回代码为-11(SIGSEGV)
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 试图对缓存进行跨步测试,但程序并没有结束
- 如何让LLDB在成功时退出,在失败时等待
- C++控制台应用程序阻止退出
- 程序在执行程序的其余部分之前退出
- 构造函数在退出函数时无法初始化一个参数
- 当调用switch语句中的函数时(即使函数不包含循环),似乎是永不结束的循环的问题
- 为什么异常不退出程序?
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 程序显示以退出代码 0; 结束
- 为什么它停止并以退出代码 11 结束?
- 程序过早结束,可能已经崩溃了.退出代码0xc0000005
- 退出(0)未结束程序
- 如何停止任务运行终端在程序以视觉工作室代码结束后自动退出
- 程序在结束时退出
- 如何在给定的openmp线程结束时退出程序
- 程序结束,退出码为10