Very Simple C++ Calculator

Posts 1–15 of 18 · Page 1 of 2
Very Simple C++ Calculator
Well this is a calculator i created in Dev-C++ with the help of tutorials and i was thinking if it was good or if there is some stuff i can do to improve it.
i have no clue what to add so some input would be a huge help.

Code:
#include <iostream>

using namespace std;

//addition
 float addition( float num1, float num2)
{ return num1 + num2; }

//subtraction
 float subtraction(float num1, float num2)
 {return num1-num2;}

//multiplication
float multiplication(float num1, float num2)
{return num1*num2;}

//division
float division(float num1, float num2)
{return num1/num2;}


//main function
int main()
{
    float number1;
    float number2;
    int choice;
    cout<<"What would you like to do?(1=add, 2=subtract, 3=multiply, 4=divide)"<<endl;
    cout<<"Choice:"<<endl;
    cin>>choice;
    
    if(choice==1)
    {//addition
    cout<<"What is your first number?(addition)"<<endl<<"Number:";
    cin>>number1;
    cout<<"What would you like to add?"<<endl<<"Number:";
    cin>>number2;
    cout<<"Your Answer is:"<<addition(number1, number2)<<endl;}
   else
   if(choice==2)
    {//subtraction
    cout<<"What is your first number(subtraction)?"<<endl<<"Number:";
    cin>>number1;
    cout<<"What number would you like to subtract?"<<endl<<"Number:";
    cin>>number2;
    cout<<"Your Answer is:"<<subtraction(number1, number2)<<endl;}
  else
  if(choice==3)
    {//multiplication
    cout<<"What is your first number(Multiplication)?"<<endl<<"Number:";
    cin>>number1;
    cout<<"What number would you like to multiply?"<<endl<<"Number:";
    cin>>number2;
    cout<<"Your Answer is:"<<multiplication(number1, number2)<<endl;}
  else
    //division
    cout<<"What is your first number(Divide)?"<<endl<<"Number:";
    cin>>number1;
    cout<<"What number would you like to Divide by?"<<endl<<"Number:";
    cin>>number2;
    cout<<"Your Answer is:"<<division(number1, number2)<<endl;
    
    system("PAUSE");
    return 0;
}
Quote Originally Posted by disturbed14x View Post
Well this is a calculator i created in Dev-C++ with the help of tutorials and i was thinking if it was good or if there is some stuff i can do to improve it.
i have no clue what to add so some input would be a huge help.
Would test this out, never know 'bout de'em runtime errors, but sadly im only running a broken linux right now, but looks nice
yeah, I've looked around the internet to try and find practice programs but when i come to one most of the time it is either this, calculator, or its the hello world program and that one is a bit to easy other than that i still have to look back sometime to check the mistakes that i made on this program.
Quote Originally Posted by disturbed14x View Post
yeah, I've looked around the internet to try and find practice programs but when i come to one most of the time it is either this, calculator, or its the hello world program and that one is a bit to easy other than that i still have to look back sometime to check the mistakes that i made on this program.
here hang on a sect, imma go get on my desktop, and test this out... hopfully the few viruses will allow me to do so
Haha, okay also if you can recommend any specific book that i can find on the internet or buy of a site that would be greatly appreciated so far i have been using a tutorial from cplusplus.com
Quote Originally Posted by disturbed14x View Post
Haha, okay also if you can recommend any specific book that i can find on the internet or buy of a site that would be greatly appreciated so far i have been using a tutorial from cplusplus.com
http://www.mpgh.net/forum/31-c-c-pro...resources.html
go there... and aslo i use Beginning Programming with C++ FOR DUMMIES because i personally knwo the author and was like why not start with it?
okay, thanks alot ill check all of those out and ill check and see if i can enter higher numbers, i used the float so i should be able to enter anything i believe correct if i am wrong( i most likely am haha).
Quote Originally Posted by disturbed14x View Post
okay, thanks alot ill check all of those out and ill check and see if i can enter higher numbers, i used the float so i should be able to enter anything i believe correct if i am wrong( i most likely am haha).
keep in touch with me? either through here(PM's) or email (in my siggy)
okay, i will Pm you and keep in touch and ask you more question.... maybe bug you a little.. just kidding or am i?
Quote Originally Posted by disturbed14x View Post
okay, i will Pm you and keep in touch and ask you more question.... maybe bug you a little.. just kidding or am i?
Its fine, Ill just try my best to help I'm currently learning C++ aswell
yeah, would be nice to have a second person going through the same thing just incase i get stuck it is still fresh in your mind.
Looks ok if it is your first program. Next time you have something this simple, do share it in the snippets thread. I am not deleting this thread though.
Quote Originally Posted by Hassan View Post
Looks ok if it is your first program. Next time you have something this simple, do share it in the snippets thread. I am not deleting this thread though.
Snippets thread is for showing our programs then? If so, I'll be making some things soon...
Quote Originally Posted by DareoTheOreo View Post
Snippets thread is for showing our programs then? If so, I'll be making some things soon...
Yes, you can post small pieces of codes there. But if you feel that the code deserves its own thread, feel free to create one.
Simple and Easy

i make one on C++ will post it
Posts 1–15 of 18 · Page 1 of 2

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us