Alright, I need help with making a function. I have tried to comprehend what the tutorial is talking about, but, unfortunately, the tutorial does a function different than what I want to do with my function.
I would paste most of my code here, but it has that 'newbie' look to it (jumpled code, because of a lack of functions). I will give a "snip-it" of the most basic thing I want to make a function of.
Code:
cout<<"It's a goblin, hurry attack."<<endl;
while (gob > 0){ //Battle Loop
attack = rand() % (HIGH - LOW + 1) + LOW;
cout<<"***Slash***"<<endl;
Sleep(1000);
cout<<"The Goblin has "<<gob - attack<<" life left!"<<endl;
gob = gob - attack;
Sleep(1500);
gobattack = rand() % (gobhi - goblo +1) + goblo;
if(gob > 0){
cout<<"***Whack***"<<endl;
Sleep(1000);
cout<<"You have "<<player - gobattack<<" life left!"<<endl;
player = player - gobattack;
Sleep(1500);
}
}
if(gob <= 0){
cout<<"Congratulations, you killed the goblin."<<endl;
}
This is basically what I want to be a function. I have this loop being called right after the selection of a weapon (since there are 3 different choices, and I can't make functions, I have 3 humongous if statements all stating the same thing, only slightly different.).
The code before the loop:
Code:
if(strcmp (answer, "2") == 0){ //First Drop --- To Buy
cout<<"Well, choose your weapon."<<endl;
cout<<"1--Sword - Damage is 4-10---"<<endl;
cout<<"2--Bow & Arrow - Damage 6-9---"<<endl;
cout<<"3--Axe - Damage 1-12---"<<endl;
cin.getline (buyanswer, 50);
if(strcmp (buyanswer, "1") == 0){ //Second Drop --- To Swd
const int LOW = 4;
const int HIGH = 10;
time(&seconds);
srand((unsigned int) seconds);
cout<<"You got a Sword!"<<endl;
Sleep(3000);
cout<<"Lets fight our first monster now. Get your sword ready!"<<endl;
Sleep(3000);
I hope I didn't give too much information, I just wanted to give as much information as I though prudent to help with my function problem.
Thanks in advance to anyone who helps me with my problem. (If anyone needs to see the ENTIRE code, I can give it in a private message, but a word of caution: it's a mess.)