How do you divide numbers in c++?
How do you divide numbers in c++?
If the explanation above isn't comprehensive enough have a look at this.
hope that helps.Code:#include <iostream.h> int main() { int num1, num2, answer; cout<<"Please enter number 1: "; cin>>num1; cout<<"Please enter number 2: "; cin>>num2; answer = num1 / num2; cout<<num1<<" divided by "<<num2<<" = "<<answer; return 0; }
But remember that when you're working with integers, everything will be rounded down. That means that 12/7=1.
To get the remainder, use modulus, %.
gcc -lalleg
http://www.ciusa.net/~jrgrant/
To get a more exact answer, use floats:
float Nr1 = 45.0;
float Nr2 = 21.0;
float Answer = Nr1 / Nr2; //Answer = 2,1428...
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.