小编Nap*_*uce的帖子

如果陈述不起作用?

我是编程的小伙子.我只是想问下面的代码有什么问题:

scanf("%i", &battlechoice);

printf("BCHOICE WAS:%i\n", battlechoice);

if (battlechoice=4) //fleeing
{
    fleechance=rand() % 100;
    if (fleechance <= 49)
    {
        printf("You attempt to flee...\n");
        sleep(2000);
        printf("Oh dear! You failed to flee! Gamover!\n");
        printf("Thank you for playing! -Anthony\n");
        sleep(7000);
        exit(0);
    } 
    else
    {
        printf("You succeeded in fleeing! You will be returned to town\nshortly...\n\n\n\n\n");
        sleep(3000);
        break;
    }
}        //end fleeing

else if (battlechoice=1) //attacking
{
    //player damage gen
    printf("You commence the attack...\n");
    sleep(750);
    damagemax = rand() % lvl * 1.4;

    damageoutcome = damagemax + …
Run Code Online (Sandbox Code Playgroud)

c if-statement scanf

0
推荐指数
1
解决办法
2751
查看次数

C反转字符串不起作用

有人可以查看此代码并检查它是否应该工作

它应该反转输入的字符串(例如"hello"应该变成"olleh")

void stringReverse (char string1[])
{

    int length, i, j, k;
    char tmp;

    length = strlen(string1);
    j = length - 1;
    printf("Length: %i",length);
    for (i = 0; i < length; i++)
    {
        tmp = string1[j];
        string1[j] = string1[i];
        string1[i] = tmp;
        j--;
    }
}
Run Code Online (Sandbox Code Playgroud)

c string reverse

-4
推荐指数
1
解决办法
87
查看次数

标签 统计

c ×2

if-statement ×1

reverse ×1

scanf ×1

string ×1