hello,

how can i call function from another function?

i declare 3 functions which are move_mid ,move_left and move_right

please see this code (it's just my idea and i know i has many syntacs erorr , but my goal is just how a function call some functions)

move_left()
{

		cout <<"press 'd' to move back to middle..."<<endl;
		cin >> current_position;
		if (current_position == 'd')
	{
		move_mid();
}
	else
	{
	cout<<"wrong"<<endl;
}
	}
void move_mid()
{
cout <<"press 'a to move left..."<<endl;
		cout <<"press 'd' to move to right..."<<endl;
		cin >> current_position;
		if (current_position == 'a')
	{
		move_left();
}
	else if (current_position == 'd')
	{
		move_right();
}
	else
	{
	cout<<"wrong"<<endl;
}
	}

as you see above, i cant do this because the function move_mid dosn't declared before the function move_left

if i change it, also still dosn't wrok

so how can i do it?

Edited 6 Years Ago by empror9: n/a

void move_left();
void move_mid();
void move_right();

Put the three lines at the top of the file or in a header file, move.h

and say

#include "move.h"

at the top of the file

I am assuming that move_right is aslo visible for compilation.

This question has already been answered. Start a new discussion instead.