【发布时间】:2014-11-05 22:22:45
【问题描述】:
我正在尝试制作一个死亡预测器,让你的角色随着你的进步而随机死亡。我要让它有多次死亡的机会,以及随着年龄的增长而增加的机会。如何修复这个基本的 rand 函数,使其 int RandomFactor 有一个 1-20 的数字并随机激活以杀死你(对不起,如果这听起来很残忍)?
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <Windows.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main() {
srand(time(NULL));
int RandomFactor;
RandomFactor = rand();
20 % 1;
for (double count = 0; count < 20; count++) {
if (count < 20) {
Sleep(360);
cout << "\n\t\t\tIt's your birthday! You turned: " << count;
}
else
if (RandomFactor == 1) {
cout << "\n\n\n\t\t\tBANG! You're dead!";
}
}
cout << "\n\n\n\t\t\t ";
return 0;
}
【问题讨论】:
-
代替
RandomFactor = rand(); 20 % 1;试试RandomFactor = rand() % 20;。 -
3 IntelliSense:预期为 ';' c:\Users\Parent\Desktop\DeathPredictionv1\DeathPredictionv1\DeathPredictionv1.cpp 18 24 DeathPredictionv1 如果我这样做,这就是我收到的错误消息。 :(
-
智能感知可能是智能的,但它不是通灵的。它无法预测您何时要进行计算。
标签: c++ loops if-statement for-loop random