Webhosting in Pakistan
Results 1 to 4 of 4

Thread: C++ Calculator For Beginner

  1. #1
    Join Date
    28 Apr 2015
    Location
    Sindh
    Gender
    Male
    Posts
    386
    Threads
    81
    Credits
    1,802
    Thanked
    38

    Default C++ Calculator For Beginner

    Webhosting in Pakistan
    C++ calculator code for beginner
    Write a simple C++ program which have four
    different functions for basic operations like
    addition, subtraction, division and
    multiplication.
    Program should be menu based asking user
    to enter option and if user enters a wrong
    option a proper message to enter right
    option should be displayed.

    Program explanation..

    Program has four different function for each

    calculator operation
    do while loop is used to display menu options
    if else statement is used to check option
    Program has two variables on which all
    basic operations are applied
    Every functions receives two parameters
    and return result

    C++ source code compiler used Codeblocks

    #include <iostream>
    using namespace std;
    int addition (int num1, int num2);
    int subtraction (int num1, int num2);
    int division (int num1, int num2);
    int multiplication(int num1, int num2);
    int main()
    {
    char option;
    int num1, num2, result;
    cout<<"\n\t\t\tSimple calculator"<<endl;
    do
    {
    cout<<"Enter + for Addtion\nEnter - for Subtraction\n
    Enter / for Division\nEnter * for Multiplication\n
    Enter E to EXIT\n";
    cout<<"\n\t\t\tEnter Option: ";
    cin>>option;
    if(option!='e'&&option!='E')
    {
    cout<<"\n\t\t\tEnter First Number: ";
    cin>>num1;
    cout<<"\n\t\t\tEnter Second Number: ";
    cin>>num2;
    }
    if(option!='+'&&option!='-'&&option!='/'
    &&option!='*'&&option!='e'&&option!='E')
    {
    cout<<"\n\t\t\tSELECT the VALID OPTION\n";
    }
    else if(option=='+')
    {
    result=addition(num1,num2);
    cout<<"\n\t\t\t"<<num1<<" + "<<num2<<" = "<<result<<endl;
    }
    else if(option=='-')
    {
    result=subtraction(num1,num2);
    cout<<"\n\t\t\t"<<num1<<" - "<<num2<<" = "<<result<<endl;
    }
    else if(option=='/')
    {
    result=division(num1,num2);
    cout<<"\n\t\t\t"<<num1<<" / "<<num2<<" = "<<result<<endl;
    }
    else if(option=='*')
    {
    result=multiplication(num1,num2);
    cout<<"\n\t\t\t"<<num1<<" X "<<num2<<" = "<<result<<endl;
    }
    }while(option!='e'&&option!='E');
    cout<<"\n\t\t\tProgram EXIT Successfully.......\n\t\t\t";
    return 0;
    }
    int addition(int num1, int num2)
    {
    return (num1+num2);
    }
    int subtraction(int num1, int num2)
    {
    return (num1-num2);
    }
    int division(int num1, int num2)
    {
    if(num2==0)
    {
    cout<<"\n\t\t\tDivide by ZERO not allowed :"<<endl;
    return 0;
    }
    return (num1/num2);
    }
    int multiplication(int num1, int num2)
    {
    return (num1*num2);
    }



    Program Output:

    Last edited by A_Qayoom; 13th August 2016 at 06:46 PM. Reason: ScreenShot Link Changed

  2. #2
    WhoWaleedSaid's Avatar
    WhoWaleedSaid is offline DriNk-dEad
    Last Online
    31st January 2020 @ 10:41 AM
    Join Date
    01 Aug 2016
    Location
    Rawalakot
    Gender
    Male
    Posts
    1,633
    Threads
    74
    Credits
    11,148
    Thanked
    93

    Default

    Great

  3. #3
    Join Date
    28 Apr 2015
    Location
    Sindh
    Gender
    Male
    Posts
    386
    Threads
    81
    Credits
    1,802
    Thanked
    38

    Default

    Quote WhoWaleedSaid said: View Post
    Great
    Tks

  4. #4
    Join Date
    15 Sep 2016
    Age
    23
    Gender
    Male
    Posts
    44
    Threads
    0
    Credits
    284
    Thanked
    0

    Default

    Webhosting in Pakistan
    Very Good

Similar Threads

  1. School Management - For Beginner
    By A_Qayoom in forum C++
    Replies: 22
    Last Post: 14th March 2019, 02:22 PM
  2. i am going to teach you SEO from beginner level
    By sani_sani in forum English IT Zone
    Replies: 11
    Last Post: 10th May 2016, 07:51 AM
  3. C Programming For Beginner
    By FritZie in forum E-Books
    Replies: 38
    Last Post: 23rd February 2015, 07:07 PM
  4. lil question about c++ beginner
    By DJCODER in forum Ask an Expert
    Replies: 8
    Last Post: 10th December 2010, 07:40 PM
  5. need for excel beginner ebook
    By smartjust4u in forum Ask an Expert
    Replies: 2
    Last Post: 17th May 2010, 04:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •