TIP: Click on subject to list as thread! ANSI
echo: nthelp
to: Geo
from: John Beckett
date: 2004-12-09 21:47:08
subject: Re: c++ help

From: John Beckett 

"Geo"  wrote in message
news::
> int n = (rand()/32767)*9999

You may want some explanation.

int a = 13;
int b = 10;

int n;
n = a / b;              // n is 1 (integer division)
n = a % b;      // n is 3 (remainder)

The reasoning is that computer hardware is capable of integer operations
AND floating point operations, and they are different. Therefore, the
language should have a way of doing both. The same symbol (/) is used for
integer division and for floating-point division.

Because a and b are integers, a / b is integer division.

float x ;
x = a / b;                      // x is 1.0 (integer division!)
x = (float)a / (float) b;       // x is 1.3

John

--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)
SEEN-BY: 633/267 270 5030/786
@PATH: 379/45 1 396/45 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.