This program runs perfect just want to know if I have to do this arithmetic operations using functions how can I do that?

// Arithmetic.cpp - This program performs arithmetic, ( +. -, *. / ) on two numbers.
// Input:  Interactive
// Output:  Result of arithmetic operation

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
int main(int argc, char *argv[]) 
{
   double numberOne, numberTwo;              	
   string operation;
   double result; 	

   cout << "Enter the first number: ";
   cin >> numberOne; 
   cout << "Enter the second number: ";
   cin >> numberTwo; 
   cout << "Enter an operator (+.-.*,/): ";
   cin >> operation;
		
   if (operation == "+")
   {
          result = numberOne + numberTwo;
                 }
          else if (operation == "-")
   {
          result = numberOne - numberTwo;
                }
          else if (operation == "*")
    {
          result = numberOne * numberTwo;
              }
          else if (operation == "/")
    {
          result = numberOne / numberTwo;
             } 

          cout << numberOne;
          cout << " " << operation << " ";
          cout << numberTwo;
          cout << " = ";
          cout << result << endl;

system("PAUSE");
return EXIT_SUCCESS;
} // End of main() function

Edited 7 Years Ago by __avd: Corrected [code] tags. Encase your code in: [code] and [/code] tags.

Wait.....what?


What do you mean? You want to do what in functions? Call a separate function to read in the input and a function to perform the math? A separate function for each arithmetic operation? You only want to have variable declarations and function calls in your main()?

Just create some functions, for example a function for addition would
look like this :

int addNumbers(int number1, int number2){
   return number1 + number2;
}

And you can do similar for other operation.

It might seem like its not worth it but doing this will make your program
neater and better.

This article has been dead for over six months. Start a new discussion instead.