帮我写一个小游戏的代码
小游戏的代码:
// This is a basic game program.
#include <iostream>
using namespace std;
int main()
{
int points = 0; // Set the initial points to 0.
cout << "Welcome to the game!" << endl; // Welcome message.
while (points < 10) { // While the player's points are less than 10...
int userInput; // Initialize a variable for user input.
cout << "Enter your number: "; // Ask for input.
cin >> userInput; // Read in user input.
if (userInput == 5) { // If they enter 5...
points++; // Increase their point total by 1.
cout << "You got it! Your point total is now: " << points << endl;
} else { // Otherwise...
cout << "Sorry, that's not right! Your point total is still: " << points << endl;
} // End of if-else statement.
} // End of while loop.
cout<<"Congrats! You have reached 10 points and won the game!"<<endl; // Print winning message once player has reached 10 points and exited loop. return 0; // Exit program with success code (0). }
创作工场
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!