Ok, i used a couple C++ programming books to help me make a calc. A friend of mine suggest that i make a "Would you like to solve another problem? (Y/N)" and Y loops back and N closes the program. here is my code:

#include <iostream.h>

int Add(int num1, int num2);
int Subtract(int num1, int num2);
int Multiply(int num1, int num2);
int Divide(int num1, int num2);

// The main procedure. When the program starts, it goes here.
int main(int argc, char *argv[])
{
  int x, y;      // Integers 'x' and 'y' - The two numbers to add
  int doNum;     // Integer 'doNum' - Add, Subtract, Multiply, or Divide?
  int b=1;       // Integer 'b' - App runs while b = 1

  while(b==1)
  {
    cout<<"Please enter two numbers with a space inbetween.press enter: ";
    cin>>x>>y;

    cout<<"Pleas press the number of what you want to do, press enter: "<<endl;
    cout<<"1. Add"<<endl;
    cout<<"2. Subtract"<<endl;
    cout<<"3. Multiply"<<endl;
    cout<<"4. Divide"<<endl;
    cin>>doNum;

    switch (doNum)
    {
      case 1:
        cout<<x<<" plus "<<y<<" = "<<Add(x, y)<<endl;
        break;
      case 2:
        cout<<x<<" minus "<<y<<" = "<<Subtract(x, y)<<endl;
        break;
      case 3:
        cout<<x<<" multiplied by "<<y<<" = "<<Multiply(x, y)<<endl;
        break;
      case 4:
        cout<<x<<" divided by "<<y<<" = "<<Divide(x, y)<<endl;
        break;
    }  //switch
  }  //while

  return 0;
}

// This function adds two variables
int Add(int num1, int num2)
{
  return num1+num2;
}

// This function subtracts two variables
int Subtract(int num1, int num2)
{
  return num1-num2;
}

// This function multiplies two variables
int Multiply(int num1, int num2)
{
  return num1*num2;
}

// This function divides the first variable by the second
int Divide(int num1, int num2)
{
  return num1/num2;
}

well i've read my books and i cant quite tell where exactly i should put the command at.

Note: this is my first real program i've made besides VBS

why not just put the whole main program inside a do while loop. then place your question before the program ends

why not just put the whole main program inside a do while loop. then place your question before the program ends

I think that's what I just said. :)

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