程序构建但不显示任何内容

时间:2015-10-23 19:09:26

标签: c++

我正在完成一项任务。我遇到的问题是每次我尝试运行我的程序以查看它显示的内容时,命令提示符上都没有显示任何内容。但是,如果我按任意键然后输入,程序将开始无法控制地循环。该程序甚至不显示初始cout消息,只是闪烁" _"。感谢

var obj = {
    "51523":{
        "firstname":"Tiki",
        "lastname":"Pur",
        "age":25
    },
    "98741":{
        "firstname":"Nagasti",
        "lastname":"Bagamba",
        "age":20
    }
}

1 个答案:

答案 0 :(得分:0)

程序中存在一些逻辑错误。现在,它应该工作正常......

#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

void PizzaMenu()
{
    cout << "Specialty Pizza Menu:" << endl;
    cout << "1) Pizza 1" << endl << "2) Pizza 2" << endl << "3) Pizza 3" << endl << "4) Pizza 4" << endl << "5) Pizza 5" << endl << "6) Exit" << endl;
}

void SizePrices()
{
    cout << "Size Prices:" << endl;
    cout << "1) 10'' Personal" << "\t" << "- $10.00" << endl;
    cout << "2) 14'' Medium" << "\t" << "- $14.50" << endl;
    cout << "3) 16'' Large" << "\t" << "- $19.00" << endl;
    cout << "4) 18'' Extra Large" << "\t" << "- $23.50" << endl;
    cout << "Your choice (1-4)? ";
}

int main()
{
    double personal = 10.00;
    double medium = 14.50;
    double large = 19.00;
    double xlarge = 23.50;
    int FlavorChoice = 0;
    int SizeChoice = 0;

    int PizzaCountP = 0;
    int PizzaCountM = 0;
    int PizzaCountL = 0;
    int PizzaCountXL = 0;
    double orderTotal = 0.0;

    cout << "Welcome to Joes pizza place!" << endl;

    cout << "Please choose from the main menu(1-6): " << endl;

    PizzaMenu();

    cin >> FlavorChoice;

    while(FlavorChoice != 6) {      

        SizePrices();

        cin >> SizeChoice;

        if (SizeChoice > 0 && SizeChoice < 5)
        {
            switch (SizeChoice)
            {

            case 1:
                cout << "How many personal pizzas? ";
                cin >> PizzaCountP;
                orderTotal += personal * PizzaCountP;
                break;
            case 2:
                cout << "How many medium pizzas?";
                cin >> PizzaCountM;
                orderTotal += medium * PizzaCountM;
                break;
            case 3:
                cout << "How many large pizzas?";
                cin >> PizzaCountL;
                orderTotal += large * PizzaCountL;
                break;
            case 4: cout << "How many extra large pizzas?";
                cin >> PizzaCountXL;
                orderTotal += xlarge * PizzaCountXL;
                break;
            default: cout << "please enter a choice (1-4)";
                cin >> SizeChoice;
                break;
            }
        }

        // orderTotal = (personal * PizzaCountP) + (medium * PizzaCountM) + (large * PizzaCountL) + (xlarge * PizzaCountXL);

        if (PizzaCountP > 0 || PizzaCountM > 0 || PizzaCountXL > 0 || PizzaCountL > 0)
        {
            // printf("Your total is: %a", orderTotal);
            cout << "Your total is: $" << orderTotal << endl;
        }

        cout << "Please choose from the main menu(1-6): " << endl;

        PizzaMenu();

        cin >> FlavorChoice;

    }

    cout << "Thank you for visiting Joes place pizza! " << endl;

    // system("pause");
    return 0;
}