基本上我正在写一个简短的脚本。最简单的查看方法是它是针对具有资源集合的游戏。ResGain 是获得的资源,BonusGain 是获得额外资源的机会。我收到 ResGain 和 Bonus Gain 函数的 Identifier not found 错误,但我在 main 之前声明了 ResGain 和 BonusGain 函数。任何想法为什么?
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
float ResGain(float u, int r) //calc Base resource Gain
{
float lapout;
lapout = r * u;
return (lapout);
}
char BonusGain(int b) //Determines if a bonus material would be produced.
{
char bonus;
int rng;
rng = rand() % 100 + 1;
if (rng <= b)
bonus = 1;
return(bonus);
}
int main()
{
float l;
l = ResGain(1.1,70);
cout << "You have earned" << l << "Lapis";
if (BonusGain(3)==1)
cout << "You have also earned a bonus material";
system("pause");
return 0;
}