程序立即关闭

时间:2013-10-29 14:47:04

标签: c++

我制作了这个程序,当我编译它时没有错误,但程序只是立即关闭,任何答案都将不胜感激。

#include <iostream> //Main commands
#include <string> // String commands
#include <windows.h> // Sleep
using namespace std;

int main ()
{
    //Declaring variables
    float a; 
    bool end; 
    std::string input;

    end = false; // Making sure program doesn't end instantly

    cout << "Enter start then the number you want to count down from." << ".\n";

    while (end = false){
        cin >> input;
        cout << ".\n";

        if (input.find("end") != std::string::npos) // Ends the program if user types end
            end = true;

        else if (input.find("start" || /* || is or operator*/ "restart") != std::string::npos) // Sets up the countdown timer if the user types start 
        {
            cin >> a;
            cout << ".\n";

            while (a>0){
                Sleep(100);

                a = a - 0.1;

                cout << a << ".\n";
            }

            cout << "Finished! Enter restart and then another number, or enter end to close the program" << ".\n";
         }

        else // Tells user to start program
        cout << "Enter start";

    }

    return 0; // Ends program when (end = true)

}

1 个答案:

答案 0 :(得分:5)

while (end = false)

这是一项任务,总是导致错误的意思,而永远不会输入

替换为while (end == false)(注意加倍==)或while (!end)以修复它