我對C++和一般編碼相當陌生。我正在嘗試爲練習做一個基本的小型多選型遊戲,但我遇到了一個難題。需要幫助輸出來自不同功能的東西(C++)
該程序不輸出我想要的東西。下面是代碼:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
void sword(int damage);
void fists(int damage);
static int enemyHealth = 250;
int main() {
srand(time(0));
string SOF; //Abreveation for "Sword Or Fists"
cout << "You will be fighting a mean bad guy. Are you using a sword, or your fists?\n";
while (SOF != "sword" && SOF != "fists"){
cout << "Please enter your choice of either 'sword' or 'fists': ";
cin >> SOF;
}
cout << "Okay! Time to fight! \n";
if (SOF == "fists") {
void fists();
}
else if (SOF == "sword") {
void sword();
}
else{ (NULL); }
cout << "Congratulations! You have vanquished that foul beast!\n";
system("pause");
}
//This is for when the user chooses 'sword'
void sword(int damage = rand() % 100 + 50) {
while (enemyHealth > 0){
cout << "You deal " << damage << " damage with your sharp sword. \n";
enemyHealth -= damage;
}
}
//This is for when the user chooses 'fists'
void fists(int damage = rand() % 10 + 4) {
while (enemyHealth > 0){
cout << "You deal " << damage << " damage with your womanly fists. \n";
enemyHealth -= damage;
}
}
第一部分工作正常,但是當我進入我的選擇,要麼"fists"
或"sword"
的輸出是:
Okay! Time to fight!
Congratulations! You have vanquished that foul beast!
但我希望它輸出的傷害正在做用拳頭或劍。
如果我能得到一些幫助,這將是驚人的。謝謝!
非常感謝你的回覆,但現在我已經糾正了錯誤,我得到了一個不同的錯誤:錯誤C2660:'拳':函數不接受0參數我收到'劍'相同的錯誤爲好。我對C++的一些小知識表示歉意,感謝您的幫助。 – buddymcdoo