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

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

c++編寫簡單的計(jì)算器程序

2020-05-23 14:05:08
字體:
供稿:網(wǎng)友
用c++語言實(shí)現(xiàn)一個(gè)簡單的計(jì)算器,新手作品,僅僅包括基本的加減乘除運(yùn)算。希望能夠給菜鳥們一些啟發(fā)
 

首先來看下本人的開發(fā)環(huán)境

系統(tǒng):win7
電腦:dell
運(yùn)行環(huán)境:vs2015
語言:c++

簡單計(jì)算器代碼

//四則運(yùn)算#include "stdafx.h"#include<iostream>#include<stdio.h>using namespace std;void add(){  printf("輸入要計(jì)算的加數(shù)(例如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("輸入要計(jì)算的減數(shù)(例如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("輸入要計(jì)算的乘數(shù)(例如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("輸入要計(jì)算的除數(shù)(例如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()//運(yùn)算函數(shù){  printf("輸入數(shù)據(jù)選擇做那種運(yùn)算/n");  printf("輸入0選擇退出,1做加法,2做減法,3做乘法,4做除法(保留余數(shù))/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)    {      //出發(fā)      division();    }    else if (operatione == 0)    {      exit(0);    }    else    {      throw 1;    }  }  catch (int i)  {    cout << "輸入錯(cuò)誤" << endl;  }  operation();} int main(){  printf("歡迎使用本計(jì)算器");  operation();  return 0;}

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



發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 亳州市| 济源市| 穆棱市| 文水县| 阳江市| 梁河县| 利辛县| 靖江市| 北宁市| 句容市| 安平县| 荣昌县| 靖州| 汤原县| 资中县| 盐城市| 贵阳市| 浑源县| 新乡县| 区。| 阳江市| 汝阳县| 务川| 建宁县| 玉溪市| 饶平县| 虎林市| 托里县| 利津县| 陇南市| 禄丰县| 高淳县| 斗六市| 龙口市| 海原县| 禄丰县| 金溪县| 福清市| 霍城县| 黄梅县| 岳普湖县|