vendredi 3 avril 2015

How do I use rand() with an enum?

Hello I'm beginning to learn c++ , I don't understand how enum works that well and I need help knowing how can I make the rand() working with enum





#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

}



}



When the default: runs in the switch() i wanted it to choose a random nature with rand(), please any help ): ?





Aucun commentaire:

Enregistrer un commentaire