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?

Recommended Answers

All 4 Replies

You need to define the functions at the top of the file
or

in a header file and then include the header file.

could you please show me in code

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.

thank you so much , it's work correctly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.