Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 2518|回复: 7
打印 上一主题 下一主题

啊 救命啊~! random number~

[复制链接]

92

主题

8

好友

4470

积分

一流名嘴

来者何人

Rank: 12Rank: 12Rank: 12

跳转到指定楼层
1#
发表于 2009-11-10 03:26 PM |只看该作者 |倒序浏览
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <ctime>
  5. using namespace std;
  6. int main ()
  7. {
  8.         int guess;
  9.         char answ;
  10.     srand (time (0));
  11.         for (int i = 0; i < 100; i++)
  12.         {
  13.         int random = rand();
  14.         int num = ((random % 100) + 1);
  15.         printf("Guess a number between 1 to 100:\n");
  16.         scanf("%d", guess);
  17.         if (guess > num)
  18.         {
  19.                 printf("the number you guess is too smaller. Try again??\n");
  20.                 continue;
  21.         }
  22.         if (guess < num)
  23.         {
  24.                 printf("the number you guess is too bigger. Try again??\n");
  25.                 continue;
  26.         }
  27.         else if (guess = num)
  28.         {
  29.                 printf("congrulation !!");
  30.                 break;
  31.         }
  32.         }
  33. return 0;
  34. }
复制代码

我走的到,不过会有问题,大家帮我查查T.T




收藏收藏0

3

主题

0

好友

2953

积分

白金长老

Rank: 10

2#
发表于 2009-11-10 04:58 PM |只看该作者
参考以下的代码:em0026

Original:
#include <iostream> // 没用到
#include <cstdlib>
#include <cmath> // 没用到
#include <ctime>
using namespace std; // 没用到
int main ()
{
        int guess;
       char answ; // 没用到
    srand (time (0));
       for (int i = 0; i < 100; i++) // 只能 loop 100 次吗?
        {
        int random = rand(); // 不应该放在 loop 里面
        int num = ((random % 100) + 1);
        printf("Guess a number between 1 to 100:\n");
        scanf("%d", guess); 应该用 &guess
        if (guess > num)
        {
                printf("the number you guess is too smaller. Try again??\n");
                continue;
        }
        if (guess < num)
        {
                printf("the number you guess is too bigger. Try again??\n");
                continue;
        }
        else if (guess = num) // 应该是 guess == num
        {
                printf("congrulation !!");
                break;
        }
        }
return 0;
}


我的:
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <ctime>

  4. int main(void)
  5. {
  6.         int iRandom, iGuess;

  7.         srand(time(0));
  8.         iRandom = rand() % 100 + 1;

  9.         do {
  10.                 printf("Guess a number between 1 to 100:\nGuess: ");
  11.                 scanf("%d", &iGuess);
  12.                
  13.                 if (iGuess > iRandom)
  14.                 {
  15.                         printf("\nThe number you entered is too large! Try again?\n");
  16.                 }
  17.                 else if(iGuess < iRandom)
  18.                 {
  19.                         printf("\nThe number you entered is too small! Try again?\n");
  20.                 }
  21.                 else
  22.                 {
  23.                         printf("Congratulation!\n");
  24.                 }

  25.         } while (iRandom != iGuess);

  26.         return 0;
  27. }
复制代码

[ 本帖最后由 Dhilip89 于 2009-11-10 05:36 PM 编辑 ]


回复

使用道具 举报

92

主题

8

好友

4470

积分

一流名嘴

来者何人

Rank: 12Rank: 12Rank: 12

3#
发表于 2009-11-10 05:57 PM |只看该作者
谢谢你哦,
刚才我在msn问你,可是你好象不得空
我的program是要

电脑自动选1个号码,然后我们来猜~

电脑选的号码不能一直调换谢谢你哦,
刚才我在msn问你,可是你好象不得空
我的program是要

电脑自动选1个号码,然后我们来猜~

电脑选的号码不能一直调换


回复

使用道具 举报

3

主题

0

好友

2953

积分

白金长老

Rank: 10

4#
发表于 2009-11-10 06:11 PM |只看该作者

回复 #3 ぁあぃ← 的帖子

哦,我是刚从学校回到来em0023


回复

使用道具 举报

13

主题

0

好友

2113

积分

白金长老

Rank: 10

5#
发表于 2009-11-10 06:32 PM |只看该作者
Dhilip89  
出手啦


回复

使用道具 举报

3

主题

0

好友

2953

积分

白金长老

Rank: 10

6#
发表于 2009-11-10 06:46 PM |只看该作者
原帖由 goodday 于 2009-11-10 06:32 PM 发表
Dhilip89  
出手啦


呵呵em0017
可以当作做练习,顺便学习em0028


回复

使用道具 举报

57

主题

18

好友

1万

积分

无敌名嘴

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

7#
发表于 2009-11-12 10:34 PM |只看该作者
刚刚也编写来玩了。。。好怀念噢!


回复

使用道具 举报

1

主题

0

好友

11

积分

初级会员

Rank: 1

8#
发表于 2010-4-14 02:25 AM |只看该作者
你的print f 好像loop 99 下了。
应该拿去loop 外面.


回复

使用道具 举报

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

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-7-3 08:26 AM , Processed in 0.109117 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部