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

后端 未结 4 1005
别那么骄傲
别那么骄傲 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:57

    One issue you have is cha[6] = 'Dieck'

    cha[6] is a single character such as 'D' or 'i' but not the whole thing. Also = sets cha[6] equal to 'Dieck' which can't happen because 'Dieck' is not a valid character. To compare them you'd need == but you can only compare one character at a time like cha[0] == 'D'

    Really you should make your input a string, and use the compare() method of the string.

    std::string input;
    // stuff
    cin >> input;
    
    if (input.compare("Dieck") == 0)
    {
       // more stuff
    }
    

提交回复
热议问题