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)
}
請編譯警告已啓用。任何來自過去十年的編譯器都會以警告的方式指出這個問題的根源。 –
使用調試器會很容易導致問題 – MrSmith42