My program loops forever and does only a half of what I told it to do

后端 未结 4 1004
别那么骄傲
别那么骄傲 2020-12-07 06:28

I\'m new to programming and I started to make my own Fire Emblem level up calculator, but for some reason it loops infinitely. I can\'t find an answer. Could you look for an

4条回答
  •  青春惊慌失措
    2020-12-07 06:52

    You have two major problems which may cause compilation error.

    nr+1;
    level-1;
    

    You have to assign them into some variable. Try this:

    nr = nr+1;
    

    or

    nr++;
    

    and

    level = level -1;
    

    or

    level--;
    

    now the while loop is not going to loop infinite.

    Second problem is

    if (cha[6] = 'Dieck' )
    

    Note that, = is an assignment operator, not an equal operator. Equal operator looks like double equal ==. As you want to compare whether cha is equal to Dieck or not, try this:

    if (strcmp (cha, "Dieck") == 0)
    

    But you need to include #include for that.

    Reference here.

提交回复
热议问题