calling function inside a function

Is this the correct way to call function in side a function

1
2
3
4
5
6
7
8
  char selectRPS(int rocks,int papers ,int scissors);//function 1
{
	if ((rockcounter==papercounter )&&(rockcounter==scissorscounter)&&(papercounter==rockcounter)&&(papercounter==scissorscounter)&&(scissorscounter==rockcounter)&&(scissorscounter==papercounter))
	{
	 cpu_choice=char random4rps(int computer, char ROCK,PAPER,SCISSORS;); //function 2
		
	}
 	

is this the correct way to call a function inside a function
Last edited on
No.

How have you been calling functions so far? Do you have any example in your code?

If not, look at: http://www.cplusplus.com/doc/tutorial/functions/


Note on your line 3.
Isn't that quite redundant? Lets replace each equality with single char:
1
2
3
4
5
if ( A && B && C && D && E && F )

// where
A = (rockcounter==papercounter)
C = (papercounter==rockcounter)

If A is true, then C is true too, isn't it? Same with B-E and D-F.

If x==y and x==z, then y==z should automatically be true (unless you have peculiar types, whose equality is weird).

Taking those in consideration, the condition simplifies to if ( A && B )

However, it is possible that overloaded operators do have side-effects and that requires the otherwise unnecessary repetition.
1
2
3
4
5
6
7
char selectRPS(int rocks,int papers ,int scissors);//a == b && a == c
{			//a			//b								//c
	if (rockcounter==papercounter && rockcounter==scissorscounter)
	
	 cpu_choice=char random4rps(int computer, char ROCK,PAPER,SCISSORS;);// still confused about this part
		
	}

okay so i have done this
Look at the tutorial. It has functions. Those functions are called.


More notes about the code fragment that you do show:

* Your function selectRPS() has parameters, but you don't use them within the function.

* What are the rockcounter, papercounter, scissorscounter, and cpu_choice? They are not local variables of the function, nor parameters of the function. I hope that they are not global variables either.
Topic archived. No new replies allowed.