How do you divide numbers in c++?

Printable View

- 05-27-2002elfjuiceDividing numbers?
How do you divide numbers in c++?

- 05-27-2002Dual-Catfish
/

- 05-28-2002UnclePunker
If the explanation above isn't comprehensive enough have a look at this.

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;

}

- 05-28-2002Boksha
But remember that when you're working with integers, everything will be rounded down. That means that 12/7=1.

- 05-28-2002JoshG
To get the remainder, use modulus, %.

- 05-28-2002Magos
To get a more exact answer, use

**float**s:

float Nr1 = 45.0;

float Nr2 = 21.0;

float Answer = Nr1 / Nr2;*//Answer = 2,1428...*