gpt4 book ai didi

C++:需要一个声明

转载 作者:行者123 更新时间:2023-11-28 02:27:29 24 4
gpt4 key购买 nike

我是一个彻头彻尾的编程菜鸟,我遇到了多个错误,上面写着“需要一个声明”分配给我们的项目需要创建一个文本基础游戏,其中包含攻击对手的角色。我们要制作角色,当我们告诉他们攻击时,我们必须输入正确的 key 进行攻击。

这是我目前所拥有的:

#include <cstdlib>
#include <Windows.h>
#include <iostream>
#include <string>

using namespace std;

int Opponent;
int showOpponentHealth(int OpponentHealth, int Attack);
int showHealth(int Health, int OpponentAttack);
int showMagic(int Magic);
{ //Error: expected a declaration
public:
Opponent() : OpponentAttack(0), OpponentHealth(3);
{
OpponentAttack = rand() % 100;
OpponentHealth = rand() % 6 + 10;
}
}
int getAttack(Opponent);
{ //Error: expected a declaration
AttRoll = Rand() % 100
if (AttRoll < getAtt)
hit
{
AttType = 1 - 3
if (AttType == 1)
return 30
else if (AttType == 2)
return 50
else if (AttType == 3)
return 70
}

float character::getHeal()
{
magicCost = magic - 6;
Heal = rand() % 3 + 5;
cout << "Heal value= " << heal << ".\n";
return Heal;
}
}
void Battle()
{
int Health = rand() % 6 + 10;
int OpponentHealth = rand() % 6 + 10;
int hit;
}
long timeTest()
{
//seed the random number generator
srand(GetTickCount64());
//rand will give a number between 0 and max integer value
int waitTime = rand() % 5 + 1;
for (int i = waitTime; i>0; i--)
{
cout << "*";
Sleep(1000); //wait for 1 second
}
char typeThis = rand() % 26 + 97;
cout << typeThis << ":";
char playerResponse;

//this is the window function I'm using to get the time: ULONGLONG WINAPI GetTickCount64(void);
ULONGLONG startTime = GetTickCount64();

cin >> playerResponse;

ULONGLONG endTime = GetTickCount64();

if (playerResponse != typeThis)
return -1;
long deltaTime = endTime - startTime;

return deltaTime;
}
do //syntax error
{ //Error: expected a declaration
cout << " Attack Opponent? \n Yes = 1\n"
cin >> Attack Opponent;
if (AttackOpponent == 1)
{
OpponentHealth = showOpponentHealth(OpponentHealth, Attack);
Health = showHealth(health, OpponentAttack);
cout << "You attacked the Opponent with a light attack.";
cout << "The Opponent now has " << OpponentHealth << "health left.";
if (OpponentHealth <= 0)
{
cout << "You Win!";
}
else if (OpponentHealth > 0)
{
cout << "Opponent attacks back";
cout << "You have" << Health << "health left,";
}

else if (AttackOpponent == 2)
cout << "You attacked the Opponent with a medium attack.";
cout << "The Opponent now has " << OpponentHealth << "health left.";
{ //Error: expected a declaration
else if (AttackOpponent == 3)
cout << "You attadcked the Opponent with a heavy attack.";
cout << "The Opponent now has " << Opponent Health << "health left.";
}
} //Error: expected a declaration
int showOpponentHealth(int OpponentHealth, int Attack)
{
OpponentHealth = OpponentHealth - Attack;
return OpponentHealth;
}
int showHealth(int Health, int OpponentAttack)
{
Health = Health - OpponentAttack;
return Health;
}
}
int main()
{
cout << "Try the timeTest: " << timeTest() << endl;

int Health = rand() % 6 + 10;
if (Health <= 0)
cout << "You Died. Game Over." << endl;

int Magic = 10
else (Magic <= 0)
cout << "No more Magic." << endl;

system("Pause");
return0;
}

错误在括号和“do”处弹出

最佳答案

您的 do{ ... } 循环在任何函数之外。它必须在一个函数内——编译器告诉你它需要一个像这样的函数声明:

long timeTest()

您是说 do-loop 是在 timeTest() 内部吗?

关于C++:需要一个声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30039295/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com