# Calculations

• 11-08-2005
bumfluff
Calculations
I am trying to make a program where I ask the user to input data about an animal and then it works out how likely they are to take over the world. How do you make a C++ Program do any sort of calculation: Multiply, Divide, Add, Subtract?
• 11-08-2005
SlyMaelstrom
All mathematical operators are standard in C and C++, just use them in your code.

Code:

```int a = 5; int b = 2; int c = a + b;  // This will equal 7 // Standard operators are: // for addition:        + // for subtraction:      - // for multiplication:  * // for division:        / // for modulus:          %```
• 11-08-2005
bumfluff
I take it you would use * for multiply and / for divide.

Oh and can you use more than one if statement in a row?
• 11-08-2005
SlyMaelstrom
You mean nested if statements? Like this:

Code:

```if (conditions) {   if (conditions) {   } }```
Yes you can do this.
• 11-09-2005
bumfluff
I know this is a very dum question but how do you show theanswer. I want to have it all in the sam line, The answer is.....
• 11-09-2005
SlyMaelstrom
I'm having trouble with your questions. They're extremely vague.

Ok, so you want to show the answer to an equation in output and you want it on the same line as text. A cout statement can accept any number of variables and constants, you just seperate each with "put to" operators and end the statement (like all statements) with a semicolon.

Code:

```int x = 5; int y = 6; int z = x + y; cout << x << " + " << y << " = " << z << endl; */ or if you prefer */ cout << "The answer is " << z << endl;```