14 Replies - 7680 Views - Last Post: 27 September 2012 - 08:06 AM

#1 josh06   User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 139
  • Joined: 27-October 06

C++ calculator

Posted 08 February 2007 - 11:10 AM

Description: N/AThis code (program) allows you to choose what calculations you want. Like Addition and Multiplication. It uses the switch statement. Thanks to Horace in the community who helped me correct the error of my ways in the program. Btw, this is only a very simple calculator and can only calculate two numbers at a time.
Now it uses a loop and quits when you want it to
#include <cstdlib>
#include <iostream>
 
using namespace std;
 
int main()
{
    double num;
    double num2;
    char choice;
    for (;;){
     do {
    cout<<"Welcome to thejoshcalculator. V1.5n";
    cout<<"Please choose an option by entering the number, press q to quitn";
    cout<<"1 - Additionn";
    cout<<"2 - Subtractionn";
    cout<<"3 - Divisionn";
    cout<<"4 - Multiplicationn";
    cout<<"5 - Helpn";
    cout<<"6 - About This Programn";
    cout<<"7 - Updates to this programn";
    cin>>choice;
    } while ( choice < '1' || choice > '7' && choice != 'q');
    if (choice == 'q') break;
    switch (choice) {
           case '1':
                cout<<"Please enter a numbern";
                cin>>num;
                cout<<"Another number to be addedn";
                cin>>num2;
                cout<<num + num2;
                cout<<"n";
                break;
           case '2':
                cout<<"Please enter a numbern";
                cin>>num;
                cout<<"Another number to be subtractedn";
                cin>>num2;
                cout<<num - num2;
                cout<<"n";
                break;
           case '3':
                cout<<"Please enter a numbern";
                cin>>num;
                cout<<"Another one to be dividedn";
                cin>>num2;
                cout<<num / num2;
                cout<<"n";
                break;
           case '4':
                cout<<"Please enter a numbern";
                cin>>num;
                cout<<"Another one to be multipliedn";
                cin>>num2;
                cout<<num * num2;
                cout<<"n";
                break;
           case '5':
                cout<<"This is a simple calculator made by me - Josh.n";
                cout<<"To select an option, type the number next to the option and press entern";
                cout<<"E.G. for division, you would type 3 and press enter.n";
                cout<<"n";
                break;
           case '6':
                cout<<"thejoshcalculator, made by Joshua Griggs - Copyright 2007. :)n";
                cout<<"Feedback would be nice - [email protected] also, what programmesn";
                cout<<"do people need. Please give me ideas for programs. Bye!!n";
                cout<<"n";
                break;
           case '7':
                cout<<"Updates include:  -double variable instead of int, so that decimals can be used.n";
                cout<<"                  -do while loop so that you can exit the program yourselfn";
                cout<<"n";
                break;
           default:
                    cout<<"That is not an option";
                    
                }
 
}
return 0;


}


Is This A Good Question/Topic? 0
  • +

Replies To: C++ calculator

#2 t_deshpande   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 30-September 08

Re: C++ calculator

Posted 30 September 2008 - 09:54 PM

thanx
Was This Post Helpful? 0
  • +
  • -

#3 Timemaster25   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-November 08

Re: C++ calculator

Posted 26 November 2008 - 06:55 AM

Thank you so much for the base of C++. This was the first type of program I have made and what I did to learn about how to make C++ is take the script apart and try to understand what each thing does.
Was This Post Helpful? 0
  • +
  • -

#4 Mayur342   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 23-December 08

Re: C++ calculator

Posted 23 December 2008 - 03:33 AM

Hi josh.. I want a simple calculator programme which do not contain any function. And this calculator perform all operation on 2 variable and after performing the one operation the user can ask about continue or exit if the usr say yes then this programme perform next operation on same value..pls give this programme...as early as possible thank you...
Was This Post Helpful? 0
  • +
  • -

#5 jaber   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 02-February 09

Re: C++ calculator

Posted 02 February 2009 - 09:43 PM

Thanks a lot for the calculator of c++.
Was This Post Helpful? 0
  • +
  • -

#6 krich87   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 03-December 08

Re: C++ calculator

Posted 17 March 2009 - 12:37 PM

Thanks a lot for this snippet, I was going in the total wrong direction with my C++ calculator, seeing this helped a lot.
Was This Post Helpful? 0
  • +
  • -

#7 Nelyn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 30-June 09

Re: C++ calculator

Posted 30 June 2009 - 12:00 AM

wow r u a programmer i want to be like u i hope im bcome of wat u r ryt now;; god bless i'm an IT studEnt from philippines.. do u have facebook just add me up [email protected]
Was This Post Helpful? 0
  • +
  • -

#8 hakeem libya   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-July 09

Re: C++ calculator

Posted 06 July 2009 - 07:34 AM

i want make sin function
Was This Post Helpful? 0
  • +
  • -

#9 anjum_nvr4gt   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 23-January 10

Re: C++ calculator

Posted 15 February 2010 - 10:05 AM

if we want to use the result of previous calculation then what shud be used,,mean if we want to perform simultaneous calculations like in real scientific calculator then.....
Was This Post Helpful? 0
  • +
  • -

#10 josh06   User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 139
  • Joined: 27-October 06

Re: C++ calculator

Posted 17 February 2010 - 03:35 AM

I was young when I wrote this and it only calculates two values at a time. Ive given up C++ now and do PHP. but feel free to edit it.
Was This Post Helpful? 0
  • +
  • -

#11 sopritenada   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 01-July 10

Re: C++ calculator

Posted 01 July 2010 - 05:06 AM

nice one but i need an infix2postfix calculator please!!!!!!! but really nice idea !!!!!
Was This Post Helpful? 0
  • +
  • -

#12 Sandrerind   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 11-June 11

Re: C++ calculator

Posted 11 June 2011 - 11:14 AM

What does the for (;;) do :-)?
Was This Post Helpful? 0
  • +
  • -

#13 Bivcala   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 31
  • Joined: 23-November 11

Re: C++ calculator

Posted 06 April 2012 - 02:17 PM

Please do your homework.
Was This Post Helpful? 0
  • +
  • -

#14 Blaylok   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 7
  • Joined: 19-August 12

Re: C++ calculator

Posted 27 September 2012 - 07:58 AM

@Sandrerind.. the for(;;) is an infinite loop! As >> the place for initialization (before the first ;) is empty, so the compiler takes a garbage value. the place for condition (between the two ;) is empty, so the compiler as default, takes it to be true. the place for updation is also empty, so again by default a garbage value is taken. However, since the condition will always return a true value so the loop will work infinitely! :D :D
Was This Post Helpful? 0
  • +
  • -

#15 Blaylok   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 7
  • Joined: 19-August 12

Re: C++ calculator

Posted 27 September 2012 - 08:06 AM

@hakeem libya: The sin function is in the math.h header file... However if you want to make one then you'll have to use some algorithm for that. for sine.. you can use this series... SIN(x) = x - ((x^3)/(3!)) + ((x^5)/(5!)) - ((x^7)/(7!)) + ..... ∞
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1