我正在做一个有趣的小项目,它本质上是一个小战斗模拟器。我试图在 C++ 中使用一个类似于 struct 的类,就像使用它来创建一个对象一样(在这种情况下,是一个字符或“实体”,因为类被称为)。尝试从主函数调用所述类中的任何整数时,标题中出现错误。
class entity{
public int health;
public int accuracy;
public int power;
public int defense;
}
Run Code Online (Sandbox Code Playgroud)
和
public class Tutorial {
static Random rnd = new Random();
entity player;
player.health = 100; // Issue on the health part
player.accuracy = 19; // Issue on the accuracy part
player.power = 15; // Issue on the power part
player.defense = 18; // I think you get it by now...
Run Code Online (Sandbox Code Playgroud)
我已经环顾了一段时间以找到一些解释,但是我找不到任何解释错误的性质以及针对我的情况的可能修复方法。如果我能得到这些,那就太好了。
所以重点是让程序找到并列出1和你输入的数字之间的所有素数.我使用number_test作为测试素数,除数和除数的数字.
我不确定是什么问题,对我来说,它看起来在功能上与此处发布的程序相同:从1到100打印素数 并进行一些小的更改(输入数字,将"i"更改为小于输入的数字).
我一直在寻找过去的三四天,而且我没有找到任何能够完全回答这个问题的东西,达到我课堂上所需要的程度.任何帮助深表感谢.
#include iostream
#include conio.h
using namespace std;
void main(void){
//Declare variables
int number_entered;
//Get inputs
cout << "This program lists all prime numbers from 1 through a positive number entered."
<< endl;
cout << "Please enter a positive integer."
<< endl;
cin >> number_entered;
cout << "Displaying all numbers from 1 to " << number_entered
<< endl
<< "Press any key to continue..."
<< endl;
getch();
for(int number_test = 2; number_test < number_entered; number_test++){
for(int …Run Code Online (Sandbox Code Playgroud)