2013-10-29 46 views
0

我做了这个程序,当我编译它时,没有错误,但程序马上关闭,任何答案将不胜感激。程序即时关闭

#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) 

} 
+4

请编译警告已启用。任何来自过去十年的编译器都会以警告的方式指出这个问题的根源。 –

+1

使用调试器会很容易导致问题 – MrSmith42

回答

5
while (end = false) 

这是一个任务,并始终会导致错误的意思,而绝不会进入

与更换任何while (end == false)(注意双==)或while (!end)修复它

+0

谢谢,它现在起作用。 –