根据某些功能编辑代码

问题描述 投票:0回答:2

我有家庭作业,家庭作业需要我做什么;

  1. 曲目长度将由程序随机确定,并且50-100米之间。 (50和100)
  2. 竞争对手的健康点(HP)为100。
  3. 障碍物数量(最小值:2最大值:5),并且将阻止出口米(Min:5〜Max:Track Length)将完全由程序随机确定。
  4. 遇到障碍的选手;如果素数范围在HP(HP)和障碍物之间,生命点将下降遇到电表。 (HP-=遇到的米)(必须检查HP和仪表之间障碍物的原始性通过使用该函数退出)

  5. 如果竞争对手成功越过最后一个障碍(HP> 0),他将将成功完成比赛并获得大奖。将。如果障碍物之后没有生命点(HP <= 0),则游戏将结束并被淘汰。

  6. 每个步骤都将记录在“ log.txt”文件中

  7. 使用程序设计之类的功能(结构,指针,动态内存,void或int)等。这很重要。

我的代码;

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>

int main()
{
    FILE *fk = fopen("log.TXT", "w");  //6- Log.TXT
    fprintf(fk,"The race started !!!\nContestant HP = 100\n");
    srand(time(NULL));
    int big,small,i,j,t;
    //1- Parkur Length 50-100
    int TrackLength = 50+rand()%51;
    //2- HP 100
    int HP=100;
    // 3- Obstacles Number (Min:2 Max:5)Obstacle Meter (Min:5 ~ Max: TrackLength)
    int ObstaclesNumber=2+rand()%4;
    int ObstacleMeter[ObstaclesNumber];
    for(int x=0; x<ObstaclesNumber; x++){ ObstacleMeter[x]=5+rand()%TrackLength;}
    // Obstacle Meter Sort
    for (i = 0; i < ObstaclesNumber-1; i++)
        for (j = 0; j < ObstaclesNumber-i-1; j++)
            if (ObstacleMeter[j] > ObstacleMeter[j+1]){
                t=ObstacleMeter[j];
                ObstacleMeter[j]=ObstacleMeter[j+1];
                ObstacleMeter[j+1] = t;}
    // 4- HP Change
    for(int z=0; z<ObstaclesNumber; z++){
        if (ObstacleMeter[z] > HP){big = ObstacleMeter[z],small = HP;}
        else{big = HP,small = ObstacleMeter[z];}
            for(int dividing=2; dividing<=small/2; dividing++){
                if( (big % dividing == 0) && (small % dividing == 0) ){
                    fprintf(fk,"The competitor did not find any obstacles up to %d meters\nThere is one obstacle at %d meters. It is not prime between %d and %d\n", ObstacleMeter[z], ObstacleMeter[z], HP, ObstacleMeter[z]);
                    fprintf(fk,"\nContestant HP = %d\n",HP);
                    break;}
                else{
                    fprintf(fk,"The competitor did not find any obstacles up to %d meters\nThere is one obstacle at %d meters. It is prime between %d and %d\n", ObstacleMeter[z], ObstacleMeter[z], HP, ObstacleMeter[z]);
                    HP -= ObstacleMeter[z];
                    fprintf(fk,"\nContestant HP = %d\n",HP);
                    if(HP<=0){ // 5- Hp<0 Control
                        fprintf(fk,"Sorry !!! You could not complete the contest.\n");
                        exit(0);}
                    break;}
                    break;}}
    fprintf(fk,"Congratulations !!! You finished the competition with %d HP.\n",HP);
}

我正在执行的程序正在运行,但已在作业(7)中指定(“结构”,“指针”,“动态内存”,“ int或void”)等。我没有使用这些功能,我不知道如何在此代码中使用它们]

您能帮忙编辑代码吗?>>

样本输出;

The race started !!!
Contestant HP = 100
The competitor did not find any obstacles up to 56 meters
There is one obstacle at 56 meters. It is not prime between 100 and 56

Contestant HP = 100
The competitor did not find any obstacles up to 62 meters
There is one obstacle at 62 meters. It is not prime between 100 and 62

Contestant HP = 100
The competitor did not find any obstacles up to 63 meters
There is one obstacle at 63 meters. It is prime between 100 and 63

Contestant HP = 37
Congratulations !!! You finished the competition with 37 HP.
    

我有家庭作业,家庭作业需要我做什么;轨道长度将由程序随机确定,长度在50至100米之间。 (50和100)竞争对手的健康点(HP)为100。...

c pointers memory-management struct
2个回答
1
投票

考虑此代码:


2
投票

在作业(7)中指定(“结构”,“指针”,“动态内存”,“ int或void”)等。我没有使用这些功能,也不知道如何在此代码中使用它们] >

© www.soinside.com 2019 - 2024. All rights reserved.