我在C++編碼,並認爲我會爲我的妹妹創造一個遊戲。但是,當我運行我的代碼時,它只運行一次,即使我有一個while循環應該使其運行無限次。我正在使用代碼塊和GCC GNU編譯器。當我運行的代碼,它的if語句之後結束後不運行COUT要麼... 下面是代碼(這是我的妹妹,所以它可能是啞):無限雖然循環不工作C++
#include <iostream>
using namespace std;
int main(){
cout << "Welcome to Uni Game" << endl;
cout << "the fun unicorn game!" << endl;
string riding;
int happiness = 0;
while (0 == 0)
{
cout << "Would you like to a: ride a unicorn b: feed your unicorn c: lead your unicorn? ";
cin >> riding;
if (riding == "a")
cout << "You jump onto your unicorn!" << endl;
cout << "You ride your unicorn through the park, seeing loads of flowers!" << endl;
cout << "After your horse eats loads of flowers, you head back to the stable." << endl;
happiness = happiness + 3;
break;
if (riding == "b")
cout << "You feed your unicorn!" << endl;
cout << "You give it its favorite wheat, which it absolutely loves!" << endl;
happiness = happiness + 2;
break;
if (riding == "c")
cout << "You grab a lead for your unicorn!" << endl;
cout << "You head to the paddock and lead your unicorn for a walk." << endl;
cout << "Your unicorn loves this!" << endl;
happiness = happiness + 1;
break;
cout << "Your happiness level is: " << happiness;
}
return 0;
}
你認爲'break'聲明有什麼用處? –
你錯過了'if'語句正文的大括號。 –
它結束如果對 – sp1d3rcr3w1an