passing variables
Dec 29, 2009 at 4:43pm UTC
I have a function that requests an integer value, so I made another function to handle the request and I wanted to pass the integer value back to the original function. How do I print the integer value in the original function? Here is the code (Hopefully not too confusing..):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
//function that I wish to print value in
void rogueBattle(){
cout << "Please select your attack:\n" ;
int rogueAttacks(int selectedAttack);
//cout << rogueAttacks(int selectedAttack); (how do I print this?)
}
int rogueAttacks(int selectedAttack){
cout << "1. Eviscerate \n" ;
cout << "2. Kidney Shot \n" ;
cout << "3. Mutilate \n" ;
cout << "4. Cloak of Shadows \n" ;
cin >> selectedAttack;
switch (selectedAttack){
case 1:
cout << "e" ;
break ;
case 2:
cout << "ks" ;
break ;
case 3:
cout << "mut" ;
break ;
case 4:
cout << "cos" ;
break ;
default :
cout << "Please select a valid option\n" ;
break ;
}
return selectedAttack;
}
Dec 29, 2009 at 5:07pm UTC
Since you are reading it with cin, you don't need selectedAttack to be a parameter:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void rogueBattle()
{
//...
cout << rogueAttacks();
}
int rogueAttacks()
{
//...
int selectedAttack;
cin >> selectedAttack;
//...
return selectedAttack;
}
Topic archived. No new replies allowed.