c++編寫簡略的盤算器法式。本站提示廣大學習愛好者:(c++編寫簡略的盤算器法式)文章只能為提供參考,不一定能成為您想要的結果。以下是c++編寫簡略的盤算器法式正文
起首來看下自己的開辟情況
體系:win7
電腦:dell
運轉情況:vs2015
說話:c++
簡略盤算器代碼
//四則運算 #include "stdafx.h" #include<iostream> #include<stdio.h> using namespace std; void add() { printf("輸出要盤算的加數(例如a b)\n"); int adda=0, addb=0,addc=0; cin >> adda; cin >> addb; addc = adda+addb; cout <<adda<<"加"<<addb<< "等於" << addc << endl; } void substraction() { printf("輸出要盤算的減數(例如a b)\n"); int suba = 0, subb = 0, subc = 0; cin >> suba; cin >> subb; subc = suba-subb; cout <<suba<<"減"<<subb<< "等於" << subc << endl; } void multiplication() { printf("輸出要盤算的乘數(例如a b)\n"); int mula = 0, mulb = 0, mulc = 0; cin >> mula; cin >> mulb; mulc = mula*mulb; cout <<mula<<"乘"<<mulb<< "等於" << mulc << endl; } void division() { printf("輸出要盤算的除數(例如a b)\n"); int dsa = 0, dsb = 0, dsc = 0,dsd=0; cin >> dsa; cin >> dsb; dsc = dsa/dsb; dsd = dsa%dsb; cout <<dsa<<"除"<<dsb<< "等於" << dsc <<"余"<<dsd<<endl; } void operation()//運算函數 { printf("輸出數據選擇做那種運算\n"); printf("輸出0選擇加入,1做加法,2做減法,3做乘法,4做除法(保存余數)\n"); int operatione = 0; cin >> operatione; cout << endl; try { if (operatione == 1) { //加法 add(); } else if (operatione == 2) { //減法 substraction(); } else if (operatione == 3) { //乘法 multiplication(); } else if (operatione == 4) { //動身 division(); } else if (operatione == 0) { exit(0); } else { throw 1; } } catch (int i) { cout << "輸出毛病" << endl; } operation(); } int main() { printf("迎接應用本盤算器"); operation(); return 0; }
代碼比擬簡略,願望年夜家可以或許愛好