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?
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?
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: %
Last edited by SlyMaelstrom; 11-08-2005 at 01:57 AM.
Sent from my iPad®
I take it you would use * for multiply and / for divide.
Oh and can you use more than one if statement in a row?
You mean nested if statements? Like this:
Yes you can do this.Code:if (conditions) { if (conditions) { } }
Sent from my iPad®
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.....
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.
If this isn't what you're asking, explain your question better.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;
Sent from my iPad®
that is exactly what i was needing. sorry i am very vague.
One of the problems was that I was posting using my PSP.