佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1038|回复: 3

要如何用C++做dice???

[复制链接]
发表于 6-9-2008 06:41 PM | 显示全部楼层 |阅读模式
我是C++的初学者,想请问下...............

我用的是borland C++, 要如何作出像dice酱,能够randomly给我一个号码??

[ 本帖最后由 Wongkokchoy 于 7-9-2008 11:17 AM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 6-9-2008 07:09 PM | 显示全部楼层
There is a restriction in C language while using the modulus operator. it can operator only on integers and cannot operate on floats or double. If anyone tries to use the modulus operator on floats then the compiler would display error message as ‘Illegal use of Floating Point’.

Let us see this with an example:
main () { float x=7,y=5; int z; z = x % y; printf( %d”, z)’; }
This above program would give error as ‘Illegal use of Floating Point’.

基本上是说 % (modulus) 必须用整数 (int).
这样行吗?

z = ((int)paid - (int)price)%(50);
回复

使用道具 举报

 楼主| 发表于 6-9-2008 07:53 PM | 显示全部楼层
------------------------------已修改-------------------------------

[ 本帖最后由 Wongkokchoy 于 6-9-2008 08:49 PM 编辑 ]
回复

使用道具 举报

发表于 7-9-2008 10:21 PM | 显示全部楼层
rand() % 6;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 27-12-2025 07:17 AM , Processed in 0.127686 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表