C + + to write a simple calculator program _c language

Source: Internet
Author: User

First look at my development environment

System: Win7
Computer: Dell
Operating Environment: VS2015
Language: C + +

Simple Calculator Code

Arithmetic #include "stdafx.h" #include <iostream> #include <stdio.h> using namespace std;
  void Add () {printf ("Enter the Addends to be evaluated (for example, a b)");
  int adda=0, addb=0,addc=0;
  Cin >> Adda;
  Cin >> ADDB;
  ADDC = ADDA+ADDB;
   
cout <<adda<< "plus" <<addb<< "equals" << addc << Endl;
  void Substraction () {printf ("Enter the meiosis to calculate (for example, a b)");
  int Suba = 0, Subb = 0, subc = 0;
  Cin >> Suba;
  Cin >> Subb;
  SUBC = Suba-subb;
cout <<suba<< "minus" <<subb<< "equals" << subc << Endl;
  void multiplication () {printf ("Enter the multiplier to be calculated (for example, a B) \ n");
  int Mula = 0, mulb = 0, Mulc = 0;
  Cin >> Mula;
  Cin >> Mulb;
  MULC = mula*mulb;
cout <<mula<< "Multiply" <<mulb<< "equals" << mulc << Endl;
  void Division () {printf ("Enter the divisor to calculate (for example, a B) \ n");
  int DSA = 0, DSB = 0, DSC = 0,dsd=0;
  CIN >> DSA;
  CIN >> DSB;
  DSC = DSA/DSB;
  DSD = DSA%DSB; cout <<dsa<< "except" <<d sb<< "equals" << DSC << "Yu" <<dsd<<endl;
  } void operation ()//operational function {printf ("input data Select to do that operation \ n");
   
  printf ("Input 0 Select exit, 1 Do addition, 2 do subtraction, 3 do multiplication, 4 do division (keep remainder) \ n");
  int operatione = 0;
  Cin >> Operatione;
  cout << Endl;
    try {if (Operatione = = 1) {//addition add ();
    else if (Operatione = 2) {//subtraction substraction ();
    else if (Operatione = 3) {//multiplication multiplication ();
    else if (Operatione = 4) {//Departure division ();
    else if (Operatione = = 0) {exit (0);
    else {throw 1;
  The catch (int i) {cout << "input error" << Endl;
} operation ();
  int main () {printf ("Welcome to use this calculator");
  Operation ();
return 0;
 }

Code is simpler, I hope you can enjoy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.