标签:visio 循环 cin row 执行 cat 返回 nbsp 抛出异常
#include <iostream> using namespace std; int division(int a, int b) //传入2个int型变量若被除数或者除数为0 则抛出异常否则返回结果 { if (a == 0) { cout << "抛出异常" << endl; throw 100; } else if (b == 0) { cout << "抛出异常" << endl; throw 101; } return a / b; } int main() { run: try { while (1) //循环输入a和b 并输出 { cout << "请输入两个正整数并执行相除操作" << endl; int a, b; cin >> a >> b; cout<<"两个数相除结果为:"<<division(a, b)<<endl; } } catch (const int m_num) { if (m_num == 100) { cout << "被除数不能为0" << endl; cout << "即将重新输入........" << endl; goto run;//返回顶部重新处理 } else if (m_num == 101) { cout << "除数不能为0" << endl; cout << "即将重新输入........" << endl; goto run; //返回顶部重新处理 } } return 0; }
标签:visio 循环 cin row 执行 cat 返回 nbsp 抛出异常
原文地址:https://www.cnblogs.com/shenji/p/12757320.html