0

案例'Y'或'y'中的以下代码调用函数randStats(),在函数返回后,我需要它来执行Switch案例中函数调用下方的代码,但它没有这样做。这可能是编译器问题,因为我过去曾遇到过 Codeblocks 问题,其中新代码似乎被完全忽略,而其他一些则没有。

这是由下面的开关调用的函数本身的粘贴:http: //ideone.com/Rx3Ig9

注意:据我所知,这不是编码问题,而是代码被完全忽略的问题。

// newchar.cpp

#include <iostream>
#include "player.h"
#include "randstats.h"
#include "newchar.h"

int new_character()
{

std::cout << "\n\nCreating new character...";
std::cout << "\n\nClaim an alias for your character: ";
std::cin >> player.alias;

char x;

std::cout << "You have chosen " << player.alias << "\n";
std::cout << "Is this correct? [y/n]: ";
std::cin >> x;

switch(x)
{
case 'y':
case 'Y':
    std::cout << "\nInserting " << player.alias << " into this hapless world of strife...";
    std::cout << "\n\nRandomizing stats...\n" << std::endl;
    randStats(); // randomize stats

    //print new character information
    std::cout << "Alias: " << player.alias << "Level: " << player.current_level << std::endl;
    std::cout << "Stats: " << player.str << "STR " << player.dex << "DEX " << player.con << "CON " << player.intel << "INT " << player.wis << "WIS " << player.cha << "CHA " << std::endl;
    break;
case 'n':
case 'N':
    std::cout << "Aborting...\n";
    break;
default:
    break;

}

//update the database
//do it


return 0;
}
4

1 回答 1

1

randstats.cpp 中的第 49 行是

// remaining_points - x;

它应该取消注释并固定为:

remaining_points -= x;

用等号。

否则,它将永远循环。

于 2013-05-23T22:31:22.537 回答