Tuesday, September 26, 2017

C++ Code Review: Basic Mathematics operations on two integer expression

Description: This program shows how to do basic mathematic operations on given two numbers. The specialty of the program is it takes expression as user input that means user has to enter the inputs along with operation symbol. Such as: 3+5, 6*7, 9/3, 25%4.

Code:

//Compiling Tool: Code::Block IDE with MinGW

//Program uses basic maths operators to do sum calculations.

 

#include<iostream>

#include<conio.h> //for getch()

#include<math.h>  //for sqrt()

#include<cstdlib> //for system()

 

using namespace std;

int main()

{

 

    system("cls");//to clear the screen

    int a,b, result;

    char c;

    cout<<"Enter two variables expression using +/-/*///% operator(Ex:25%4):";

    cin>>a>>c>>b;

 

    switch(c)

    {

    case'+':

        result = a+b;

        break;

 

    case'-':

        result = a-b;

        break;

 

    case'*':

        result = a*b;

        break;

 

    case'/':

        result = a/b;

        break;

 

    case'%':

        result = a%b;

        break;

    }

    cout<<"Result:"<< result;

    getch();

    return(0);

}

 

Output:

clip_image002

If you want to write or construct or program C++ mini-project and do not know how or from where to start buy this simple e-book: Code Review of 26 C++ mini-projects. For book sample click this link.

Add your comments in below available comment box.

Note: Click these label/tags to view all related posts. Tags: C++Code

 

…till next post, bye-bye & take care.

No comments:

Post a Comment