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 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<<"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
{
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;
}``````
3
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by Ancient Dragon

Ok, so you want to add that feature. What is your question ?

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

I would probably put that prompt between lines 41 and 42.

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.