// Guess my number
// My first text based game
// Created by USDlades
// http://www.USDgamedev.zxq.net
#include <cstdlib>
#include <ctime>
#include <string>
#include <iostream>
using namespace std;
int main()
{
srand(static_cast<unsigned int>(time(0))); // seed the random number generator
int guess;
int secret = rand() % 100 + 1; // Generates a Random number between 1 and 100
int tries =0;
cout << "I am thinking of a number between 1 and 100, Can you figure it out?\n";
do
{
cout << "Enter a number between 1 and 100: ";
cin >> guess;
cout << endl;
tries++;
if (guess > secret)
{
cout << "Too High!\n\n ";
}
else if (guess < secret)
{
cout << "Too Low!\n\n ";
}
else
{
cout << "Congrats! you figured out the magic number in " <<
tries << " tries!\n";
}
} while (guess != secret);
cin.ignore();
cin.get();
return 0;
}
我的代碼在我的電腦上運行良好,但是當我的一個朋友試圖運行它,程序崩潰。這是否與我的編碼有關?我還發現,當我輸入一個猜測信時,我的遊戲進入無限循環。我該如何解決這個問題?C++猜數遊戲崩潰在其他計算機和無限循環修復
所以... *它怎麼會崩潰?在什麼操作系統上?用什麼輸入? – 2011-06-01 03:26:30
當她在Windows Vista Premium上打開它時,它崩潰,甚至沒有加載我的遊戲我不認爲 – USDblades 2011-06-01 03:27:42
它在崩潰時顯示在屏幕上的消息是什麼? (如果你還不知道,*找出*,這可能會直接導致解決您的問題。) – 2011-06-01 03:28:40