你好,我开始学习C++,我不知道如何枚举工作那么好,我需要帮助,我知道如何让兰特()与枚举如何在枚举中使用rand()?
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
cout << "First part : Create an item. " << endl;
int choice;
int Fire = 25;
int Water = 23;
int Wind = 24;
int Earth = 20;
int WeaponNature = 0;
enum NatureWeapons { Fire, Water, Wind, Earth}; // enum here if its wrong pls let me know):
cout << "Enter the nature of weapon you want : " << endl;
cout << " 1 - Fire " << endl;
cout << " 2 - Water " << endl;
cout << " 3 - Wind " << endl;
cout << " 4 - Earth" << endl;
cin >> choice;
switch(choice)
{
case 1:
cout << "You picked fire."
cout << " Power : " << Fire << endl;
WeaponNature = Fire;
break;
case 2:
cout << "You picked water." << endl;
cout << " Power : " << Water << endl;
WeaponNature = Water;
break;
case 3:
cout << "You picked wind nature." << endl;
cout << " Power : " << Wind << endl;
WeaponNature = Wind;
break;
case 4:
cout << "You picked earth nature." << endl;
cout << " Power : " << Earth << endl;
WeaponNature = Earth;
break;
default:
cout << "Incorrect input. Your weapon will be : " << rand() // this is where i need help
}
}
工作当默认值:在switch()中运行时,我希望它使用rand()选择随机性质,请任何帮助):?
在这种情况下,C++中的枚举只是一系列int(0-3)的简便表示。 – 2015-04-04 04:53:09
如何在默认情况下使用rand():? – Cereal 2015-04-04 04:56:24