Page 1 of 2 12 LastLast
Results 1 to 12 of 16

Thread: Basic Calculator + Source!

  1. #1
    SufyanGujar is offline Senior Member+
    Last Online
    29th December 2010 @ 10:59 PM
    Join Date
    10 Oct 2009
    Location
    England, UK
    Age
    34
    Posts
    157
    Threads
    10
    Credits
    0
    Thanked
    7

    Default Basic Calculator + Source!

    Hi Guys!

    Yeh mera calculator aur source file hai.
    Basically you will see use of for and while loop
    as well as Switch statements.

    Source Code:
    Code:
    #include <cstdlib>
    #include <iostream>
     
    using namespace std;
     
    int main()
    {
        double num;
        double num2;
        char choice;
        for (;;){
         do {
        cout<<"Welcome to Saif's Calculator\n\n";
        cout<<"Please select options by entering the number. To Exit/Quit press 'Q'.\n";
        cout<<"1 - Addition\n";
        cout<<"2 - Subtraction\n";
        cout<<"3 - Division\n";
        cout<<"4 - Multiplication\n";
    
        cin>>choice;
        } while ( choice < '1' || choice > '4' && choice != 'q');
        if (choice == 'q') break;
        switch (choice) {
               case '1':
                    cout<<"Please enter First Number\n";
                    cin>>num;
                    cout<<"Now Enter Second Number to Add.\n";
                    cin>>num2;
                    cout << "Ans = ";
                    cout<<num + num2 << endl;
                    
                    break;
               case '2':
                    cout<<"Please enter First Number\n";
                    cin>>num;
                    cout<<"Now Enter Second Number subtract.\n";
                    cin>>num2;
                    cout << "Ans = ";
                    cout<<num - num2;
                    cout<<"\n";
                    break;
               case '3':
                    cout<<"Please enter First Number\n";
                    cin>>num;
                    cout<<"Now Enter Second Number to divid\n";
                    cin>>num2;
                    cout << "Ans = ";
                    cout<<num / num2;
                    cout<<"\n";
                    break;
               case '4':
                    cout<<"Please enter First Number\n";
                    cin>>num;
                    cout<<"Now Enter Second Number to multiply\n";
                    cin>>num2;
                    cout << "Ans = ";
                    cout<<num * num2;
                    cout<<"\n";
                    break;
    
               default:
                        cout<<"There is no such option.";
                        
                    }
     
    }
    return 0;
    
    
    }
    Link for Calculator Excuteable file(.exe) and source file(.cpp).
    Link -->C++ Calculator and Source file

    Aap khud bhe compile kar saktein hain. Hope you Guys Like it.
    Thnx

  2. #2
    MailKing is offline Senior Member+
    Last Online
    19th December 2013 @ 04:05 PM
    Join Date
    17 Aug 2009
    Posts
    400
    Threads
    20
    Credits
    1,030
    Thanked
    19

    Default

    Thanks for sharing...

  3. #3
    Helper 558 is offline Senior Member+
    Last Online
    20th September 2022 @ 04:34 PM
    Join Date
    22 Sep 2009
    Location
    Multan (Pakistan)
    Age
    35
    Gender
    Male
    Posts
    139
    Threads
    9
    Credits
    1,212
    Thanked
    3

    Default

    Yar yeh commond bil kul aisy he type karni hy kia koi btao i love programing

  4. #4
    oLd i$ gOlD's Avatar
    oLd i$ gOlD is offline Senior Member+
    Last Online
    8th March 2012 @ 04:31 PM
    Join Date
    06 Jun 2009
    Location
    Karachi
    Age
    31
    Posts
    170
    Threads
    17
    Credits
    802
    Thanked
    5

    Default

    too long codes not have any short codes?

  5. #5
    intelligent is offline Senior Member+
    Last Online
    24th December 2013 @ 09:57 AM
    Join Date
    29 Jun 2008
    Location
    Lahore
    Posts
    620
    Threads
    14
    Credits
    0
    Thanked
    24

    Default

    ya it is possible with a short code!

  6. #6
    SufyanGujar is offline Senior Member+
    Last Online
    29th December 2010 @ 10:59 PM
    Join Date
    10 Oct 2009
    Location
    England, UK
    Age
    34
    Posts
    157
    Threads
    10
    Credits
    0
    Thanked
    7

    Default

    Quote Ahsanfk said: View Post
    too long codes not have any short codes?
    Well it dosent matter how long code is,
    if u understand the code u will find it
    very easy, anyway here is simplest
    as well as commented code, all u gta
    do is add cout statements where ever u
    want to;

    Code:
    #include <iostream> // handle input and outputs
    
    using namespace std; // using std, to avoid using std:: each time
    
    int main()  // function starts
    {
        double MyVar, MyVar2, Result; // Declared variables
        char Sign;                   // to handle calculations
        
        cin >> MyVar >> Sign >> MyVar2; // Getting input from user.
        
           if (Sign == '+') // Testing condition using
        {
         Result = MyVar + MyVar2; // do calculation according to condition
         }
         
         else if (Sign == '-')
        {
         Result = MyVar - MyVar2;
         }
         else if (Sign == '*')
        {
         Result = MyVar * MyVar2;
         }
         
         else if (Sign == '/')
        {
         Result = MyVar / MyVar2;
         }
         
         cout << "Answer: " << Result << endl; // finally print result of the calculations to screen
    
    	system ("PAUSE"); // Pause the screen so that user can see the answer at end
    	return 0; 
    
    }
    In case u dont know, writing after // is jst to tell u what it is,
    that is not included in code.
    if u r still confused then try this:
    Code:
    #include <iostream> 
    using namespace std;
    
    int main() { double MyVar, MyVar2, Result;
                 char Sign;
        
        cin >> MyVar >> Sign >> MyVar2;
        
        if (Sign == '+') {Result = MyVar + MyVar2; }
         else if (Sign == '-') { Result = MyVar - MyVar2;}
         else if (Sign == '*') {Result = MyVar * MyVar2;}
         else if (Sign == '/') {Result = MyVar / MyVar2;}
         
         cout << "Answer: " << Result << endl;
    
    	system ("PAUSE");
        return 0; }
    -Saif

  7. #7
    SufyanGujar is offline Senior Member+
    Last Online
    29th December 2010 @ 10:59 PM
    Join Date
    10 Oct 2009
    Location
    England, UK
    Age
    34
    Posts
    157
    Threads
    10
    Credits
    0
    Thanked
    7

    Default

    Quote Helper 558 said: View Post
    Yar yeh commond bil kul aisy he type karni hy kia koi btao i love programing
    gi bhai, yeh same to same copy karna hai,

  8. #8
    heroofdikhan's Avatar
    heroofdikhan is offline Senior Member
    Last Online
    2nd July 2018 @ 11:48 AM
    Join Date
    31 May 2007
    Location
    ~:::Ghar me:::~
    Age
    33
    Posts
    1,081
    Threads
    160
    Credits
    1,052
    Thanked
    89

    Default

    fazoooooooooooolll hai aik simple calculator aur itni long programming
    programming ka pehla asul hee ye hai k short aur efficient flexible ho
    :::[FONT="Fixedsys"]Forget injuries but never forget kindness[/FONT]:::

    [CENTER] [SIGPIC][/SIGPIC][/CENTER]

  9. #9
    qaisarmughal83 is offline Senior Member+
    Last Online
    28th January 2023 @ 04:57 PM
    Join Date
    22 Jan 2009
    Age
    40
    Posts
    110
    Threads
    0
    Credits
    1,287
    Thanked
    2

    Default

    thanx jnab.

  10. #10
    intelligent is offline Senior Member+
    Last Online
    24th December 2013 @ 09:57 AM
    Join Date
    29 Jun 2008
    Location
    Lahore
    Posts
    620
    Threads
    14
    Credits
    0
    Thanked
    24

    Default

    switch statement ke bager b ho jana tha but good!
    Abdullah Zaib

  11. #11
    blackberry is offline Senior Member+
    Last Online
    20th August 2012 @ 09:52 AM
    Join Date
    03 Jan 2010
    Location
    Heaven
    Gender
    Female
    Posts
    171
    Threads
    10
    Credits
    1,085
    Thanked
    4

    Default

    thanks for sharing all source codes.... will compile it later ...

    great job!!!

  12. #12
    M-Qasim's Avatar
    M-Qasim is offline Advance Member+
    Last Online
    7th September 2022 @ 07:41 PM
    Join Date
    22 Mar 2009
    Gender
    Male
    Posts
    33,351
    Threads
    915
    Credits
    1,718
    Thanked
    3391

    Default

    Very Nice Sharing

    Thanks for Sharing With Us

Page 1 of 2 12 LastLast

Similar Threads

  1. Calculator in Visual Basic 6
    By iTExpert in forum General Discussion
    Replies: 23
    Last Post: 14th April 2012, 11:26 AM
  2. Solved Scientific Calculator Source Code
    By suleman115 in forum Solved Problems (IT)
    Replies: 21
    Last Post: 1st January 2011, 08:36 PM
  3. how to make an calculator in gw basic
    By mdhamza in forum Ask an Expert
    Replies: 7
    Last Post: 5th August 2009, 06:39 AM
  4. Replies: 2
    Last Post: 12th February 2009, 07:43 AM

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
  •