国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

c++編寫簡單的計算器程序

2020-01-26 14:37:25
字體:
來源:轉載
供稿:網友

首先來看下本人的開發環境

系統: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;}

代碼比較簡單,希望大家能夠喜歡

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 台南县| 韶关市| 湛江市| 株洲县| 荔波县| 武陟县| 温宿县| 东乌珠穆沁旗| 新龙县| 邵阳市| 兴安县| 威宁| 定州市| 周宁县| 卢龙县| 武宣县| 翁源县| 阿拉善盟| 昌都县| 临泉县| 罗城| 秦皇岛市| 萨迦县| 苍山县| 津市市| 西乡县| 晋中市| 三台县| 遂溪县| 安图县| 安阳县| 鹤山市| 静乐县| 乌海市| 万源市| 萨嘎县| 安宁市| 千阳县| 阿鲁科尔沁旗| 丘北县| 甘孜县|