C++ Program to Make a Simple Mathematical calculator

On this lesson we will examine C++ Program to Make a Simple Mathematical calculator via the use of switch statement. First we define switch shape and see syntax of transfer structure of c/c++ language.

Calculator in c programming

definition and syntax of transfer structure are as follows
you could replica and make a supply document compiler
to recognize the instance you must have the know-how approximately syntax of case announcement and primary structure of c++. This application takes an mathematics operator (+, -, *, /) and operands from user and performs the operation on the ones operands depending upon the operator.

# encompass <iostream. H>
#encompass <conio. H>
void important()

char op;
drift n1, n2;
cout << “enter operator + or – or * or /: “;
cin >> op;
cout << “enter two operands: “;
cin >> n1 >> n2;
switch(op)

case ‘+’:
cout << n1+n2;
damage;
case ‘-‘:
cout << n1-n2;
damage;
case ‘*’:
cout << n1*2;
spoil;
case ‘/’:
cout << n1/n2;
spoil;
case ‘/’:
cout << n1%n2;
wreck;
default:
cout << “incorrect oprater plz inter +,-,*,/ or %”;
destroy;

getch();

c software for simple calculator

c++ and c have nearly identical structure however only some differences

in c++ prepossess directive iostream. H is used for such as stranded enter output functions even as in c program languageperiod stdio. H is used
for output cout is used in c++ while in c language printf is used for output (C++ Program to Make a Simple Mathematical calculator)
in c++ cin is used for getting enter from the person whilst in c coding scanf function is used for buying input from the person. In c++ format specifier aren’t used to print output and for buying enter at the same time as layout specifier are utilized in c coding.
# encompass <stdio. H>
#consist of <conio. H>
void most important()

clrscr();
char op;
waft n1, n2;
printf( “enter operator + or – or * or /: “);
scanf(“%c”,op);
printf( “input operands: “);
scanf(“%f %f”,&n1,&n2);
transfer(op)

case ‘+’:
printf(“%f”, n1+n2);
destroy;
case ‘-‘:
printf(“%f”, n1-n2);
wreck;
case ‘*’:
printf(“%f”, n1*n2);
wreck;
case ‘/’:
printf(“%f”, n1/n2);
ruin;
case ‘%’:
printf(“%f”, n1p. Cn2);
wreck;
default:
printf(“incorrect oprater plz inter +,-,*,/ or %”);
damage;

getch();

Add a Comment

Your email address will not be published.