Write a simple calculator program in C + +

Source: Internet
Author: User

050305.cpp: Defines the entry point of the console application.
//

050304.cpp: Defines the entry point of the console application.
//
Arithmetic
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
using namespace Std;
void Add ()
{
printf ("Enter the Addend to be computed (e.g. a b) \ n");
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 be computed (e.g. a b) \ n");
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 computed (e.g. 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 be computed (e.g. 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" <<dsb<< "equals" << DSC << "remainder" <<dsd<<endl;
}
void operation ()//Arithmetic function
{
printf ("Input data choose to do that operation \ n");
printf ("Input 0 opt out, 1 do addition, 2 do subtraction, 3 do multiplication, 4 do division (preserve 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)
{
Let's go
Division ();
}
else if (Operatione = = 0)
{
Exit (0);
}
Else
{
Throw 1;
}
}
catch (int i)
{
cout << "Input error" << Endl;
}
Operation ();
}

int main ()
{
printf ("Welcome to use this calculator");
Operation ();
return 0;
}

Technical exchange [email protected]

Or come to me another blog exchange: http://www.oschina.net/code/snippet_2743162_55878

Or: http://blog.csdn.net/schopenhauerzhang/article/details/51308392

Welcome to my mailbox or blog messages, technical exchanges; [Email protected]

Write a simple calculator program in C + +

Related Article

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.