Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;假设值为0,程序在cin后结束_C++ - Fatal编程技术网

C++ C++;假设值为0,程序在cin后结束

C++ C++;假设值为0,程序在cin后结束,c++,C++,我正在尝试制作一个程序,用于计算一个名为Magic the Gathering的游戏的卡片余额,但每当我尝试运行这个程序时,它都会在main中的第一个“cin”处停止,调试显示它正在生成numMana 0。我是C++新手,我知道我可以把它分成更多的函数或类,或者C++中的任何东西。如果你能给我任何帮助,我将不胜感激 谢谢你的帮助, 授予 代码如下: #include <iostream> #include <string> using namespace std; f

我正在尝试制作一个程序,用于计算一个名为Magic the Gathering的游戏的卡片余额,但每当我尝试运行这个程序时,它都会在main中的第一个“cin”处停止,调试显示它正在生成numMana 0。我是C++新手,我知道我可以把它分成更多的函数或类,或者C++中的任何东西。如果你能给我任何帮助,我将不胜感激

谢谢你的帮助, 授予

代码如下:

#include <iostream>
#include <string>

using namespace std;

float getGreen(void);
float getBlue(void);
float getRed(void);
float getBlack(void);
float getWhite(void);
int cardNum(void);
int numMana;
float color;

int main(void)
{
    cout << "How many mana are there total on the cards" << endl;
    cout << "not counting multi-colored" << endl;
    cin >> numMana;
    cout << endl;

    float green(getGreen());
    float blue(getBlue());
    float red(getRed());
    float black(getBlack());
    float white(getWhite());
    int cardsPre(cardNum());

    int numGreen, numBlue, numRed, numBlack, numWhite, mana, totalCards, totalMana;

    string name;

    mana = (cardsPre / 2);

    numGreen = green * mana;
    numBlue = blue * mana;
    numBlack = black * mana;
    numRed = red * mana;
    numWhite = white * mana;

    totalMana = numWhite + numRed + numGreen + numBlue + numBlack;
    totalCards = mana + totalMana;

    cout << "What would you like to name your deck?" << endl;
    cin >> name;
    cout << endl;

    cout << name << " has the following percents of each color" << endl;
    cout << green << "% of green" << endl;
    cout << blue << "% of blue" << endl;
    cout << red << "% of red" << endl;
    cout << black << "% of black" << endl;
    cout << white << "% of white" << endl;
    cout << "You need" <<numGreen << " green mana" <<endl;
    cout << "You need" <<numBlue << " blue mana" << endl;
    cout << "You need" <<numRed << " red mana" << endl;
    cout << "You need" <<numBlack << " black mana" << endl;
    cout << "You need" <<numWhite << " white mana" << endl;
    cout << "You will have" <<totalCards <<" cards in your deck";
    return 0;
}

float getGreen(void)
{
    cout << "How much green mana is there total on your cards?" << endl;
    cin >> color;

    return color / numMana;
}
float getBlue(void)
{
    cout << "How much Blue mana is there total on your cards?" << endl;
    cin >> color;

    return color / numMana;
}
float getRed(void)
{
    cout << "How much Red mana is there total on your cards?" << endl;
    cin >> color;

    return color / numMana;
}
float getBlack(void)
{
    cout << "How much Black mana is there total on your cards?" << endl;
    cin >> color;

    return color / numMana;
}
float getWhite(void)
{
    cout << "How much White mana is there total on your cards?" << endl;
    cin >> color;

    return color / numMana;
}
int cardNum(void)
{
    int ans;

    cout << "How many cards do you have (Not counting mana)" << endl;
    cin >> ans;

    return ans;
}
#包括
#包括
使用名称空间std;
浮点数为绿色(无效);
浮蓝(无效);
浮点数为红色(无效);
浮点数为黑色(无效);
白色浮动(无效);
int cardNum(无效);
国际货币基金组织;
浮色;
内部主(空)
{

它能在我的机器上工作吗?你输入了一些无法转换为整数的东西…我没有遇到任何问题。除了%-计算外,该程序似乎工作正常。每个%-值的输出都应该乘以100。在我的机器上,我没有机会输入任何东西。这种情况发生了:我不能输入任何东西并按enter doen不执行任何操作您似乎正在通过调试器运行程序,并且已在
cin>>numMana;
设置了断点。断点将在指定的源代码行“暂停”程序的执行。请删除断点或尝试在未连接调试器的情况下运行程序。