几周前我刚开始尝试使用C++.在尝试使用C++之前,我对Java有了相当不错的把握.很多人告诉我他们在语法方面非常相似.
在底部有一个switch语句启动战斗场景.每当我选择战斗选项时,它就会关闭程序.
这是我的代码:
#include "stdafx.h"
#include <iostream>
#include <cstdlib> // For rand()
#include <string>
#include <sstream>
#include <algorithm> // transform()
#include <cctype> // toupper(), tolower()
#include <functional> // ptr_fun()
#include <time.h>
// PUT S*** BELOW THIS POINT
//____________________________________________________________________________
using namespace std;
int main()
{
/* Expirimental text based adventure game.
* Mainly being used for practice methods.
* Developed by Zack Cook.
Generic title. Bad story. Bad interactions.
Lots and lots of bad, bad code. Be warned.
*/
string charName; …Run Code Online (Sandbox Code Playgroud) 它只是保持循环.数字继续减少,直到该计划结束.我滥用了什么吗?
playerHealth和orcHealth ints是100.
randomNumber = ("%10d", 1 + (rand() % 100));
Run Code Online (Sandbox Code Playgroud)
这是我在srand()解释页面上看到的随机数的方式.如果这是错的,应该怎么做?
这里还有其他问题吗?
switch(charDecision)
{
case 1:
cout << "FIGHT" << endl;
do{
randomNumber = ("%10d", 1 + (rand() % 100));
if(randomNumber >= 50){
orcHealth = orcHealth - (randomNumber - (randomNumber / 5));
cout << "You hit the orc! He now has " << orcHealth << " life left!" << endl;
}
else
{
playerHealth = playerHealth - (randomNumber - (randomNumber / 5));
cout << "The orc hit you! You …Run Code Online (Sandbox Code Playgroud)