我的教授强迫我使用一个名为 RAPTOR 的程序,它可以创建和执行流程图和伪代码。而且我一直在转换我的流程图,而不是用实际语言编写。我终于编译了我的程序,但现在它不会给我与 RAPTOR 程序相同的结果,并且我的 black1 变量一直返回 0,而 black2 一直在吐出一个像 1,000 这样的数字。无论如何,任何帮助将不胜感激,谢谢!
这是代码:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main()
{
int trials;
int first;
string bag;
int j;
float percent;
string temp;
int black2;
int runs;
int l;
int black1;
int firstdraw;
int c;
string possible;
int seconddraw;
srand(time(NULL));
l = bag.length();
int r = rand() % 4;
possible ="bw";
runs =0;
while (!(runs>9))
{
black1 =0;
black2 =0;
runs =runs+1;
trials =0;
while (!(trials==1000))
{
trials =trials+1;
bag ="bbwww";
l = bag.length();
c =1;
temp =" ";
while (!(c==5))
{
j = r ;
temp[1] = bag[c];
bag[c] = bag[j];
bag[j] = temp[1];
c =c+1;
}
c =1;
j = r;
firstdraw =bag[j];
if (firstdraw==possible[1])
{
black1 = black1+1;
first = 1;
}
else
{
first = 0;
}
while (!(j>l-1))
{
bag[j] = bag[j + 1];
j =j+1;
}
l =l-1;
j = r;
seconddraw = bag[j];
if (seconddraw==possible[1] && first==1)
{
black2 =black2+1;
}
else
{
}
}
percent = 100.0 * black2/black1;
cout << black2 << " " << black1 << endl;
cout << "Percentage for run #" << runs << " and " << trials << " trials: %" << percent << endl; }
return 0;
}