c++編寫(xiě)簡(jiǎn)單的計(jì)算器程序
首先來(lái)看下本人的開(kāi)發(fā)環(huán)境
系統(tǒng):win7
電腦:dell
運(yùn)行環(huán)境:vs2015
語(yǔ)言:c++
簡(jiǎn)單計(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; }
代碼比較簡(jiǎn)單,希望大家能夠喜歡
- 簡(jiǎn)單實(shí)現(xiàn)C++復(fù)數(shù)計(jì)算器
- C/C++實(shí)現(xiàn)日期計(jì)算器的示例代碼
- C++有限狀態(tài)機(jī)實(shí)現(xiàn)計(jì)算器小程序
- C/C++經(jīng)典實(shí)例之模擬計(jì)算器示例代碼
- C++實(shí)現(xiàn)簡(jiǎn)單計(jì)算器
- C++實(shí)現(xiàn)四則混合運(yùn)算計(jì)算器
- C++實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
- C++實(shí)現(xiàn)分?jǐn)?shù)計(jì)算器
- 基于C++實(shí)現(xiàn)簡(jiǎn)單日期計(jì)算器
- C++制作簡(jiǎn)單的計(jì)算器功能
相關(guān)文章
VS?Code安裝及C、C++環(huán)境配置詳細(xì)教程(Windows系統(tǒng))
這篇文章主要介紹了VS?Code安裝及C、C++環(huán)境配置詳細(xì)教程(Windows系統(tǒng)),本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-02-02C++?qt實(shí)現(xiàn)打開(kāi)關(guān)閉狀態(tài)按鈕的代碼
這篇文章主要介紹了C++?qt實(shí)現(xiàn)打開(kāi)關(guān)閉狀態(tài)按鈕,用QCheckBox可以實(shí)現(xiàn),只要在選擇與未選擇的狀態(tài)設(shè)置不同的圖片即可完成,代碼簡(jiǎn)單易懂,需要的朋友可以參考下2022-03-03更優(yōu)雅的C++字符串格式化實(shí)現(xiàn)方法詳解
在用C++編寫(xiě)代碼時(shí),經(jīng)常需要用到字符串拼接及格式化,尤其是在拼寫(xiě)sql語(yǔ)句時(shí)。所以本文為大家介紹了更優(yōu)雅的C++字符串格式化實(shí)現(xiàn)方法,希望對(duì)大家有所幫助2023-04-04基于C語(yǔ)言?huà)呃子螒虻脑O(shè)計(jì)與實(shí)現(xiàn)
大家好,本篇文章主要講的是基于C語(yǔ)言?huà)呃子螒虻脑O(shè)計(jì)與實(shí)現(xiàn),感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話(huà)記得收藏一下,方便下次瀏覽2021-12-12