代码未在Switch内部执行功能后执行

时间:2013-05-23 18:58:08

标签: c++ switch-statement codeblocks

调用函数randStats()时,在函数'Y'或'y'中调用以下代码,在函数返回后,我需要它来执行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;
}

1 个答案:

答案 0 :(得分:1)

randstats.cpp中的第49行是

// remaining_points - x;

它应该被取消注释并修复为:

remaining_points -= x;

等号。

否则,它会永远循环。