recursive on all control paths

hi, I searched for this error and found that it arises from function calling itself over and over, where does my code do this?

#include <iostream>
using namespace std;
//function prtototypes
void ReadShapeDimensions();
float calculateBasicVolume(double r ,double h);
void printResult();
int ReadInputShapeChoice(){
int choice;
float volume;
cout<<"Volume calculator\n\nPlease select a shape:\n(1)Cylinder\n(2)Cone\n";
cin>>choice;
ReadShapeDimensions();{
double r, h;
cout<<"Please enter the radius of the shape\n";
cin>>r;
cout<<"Please enter the height/length of the shape\n";
cin>>h;
calculateBasicVolume(r,h);
if (choice=1){
volume=3.14*r*r*h;
}
else if (choice=2){
volume=0.33*3.14*r*r*h;
}
printResult();{
cout<<"Volume = "<<volume<<"u^3";
}

}
int main();{
ReadInputShapeChoice();

return 0;
}
}



output:
1>------ Build started: Project: Workshop13_task2, Configuration: Debug Win32 ------
1> task2.cpp
1>c:\users\pin\documents\visual studio 2012\projects\workshop13_task2\workshop13_task2\task2.cpp(20): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\users\pin\documents\visual studio 2012\projects\workshop13_task2\workshop13_task2\task2.cpp(23): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\users\pin\documents\visual studio 2012\projects\workshop13_task2\workshop13_task2\task2.cpp(35): warning C4717: 'ReadInputShapeChoice' : recursive on all control paths, function will cause runtime stack overflow
1>task2.obj : error LNK2019: unresolved external symbol "void __cdecl ReadShapeDimensions(void)" (?ReadShapeDimensions@@YAXXZ) referenced in function "int __cdecl ReadInputShapeChoice(void)" (?ReadInputShapeChoice@@YAHXZ)
1>task2.obj : error LNK2019: unresolved external symbol "float __cdecl calculateBasicVolume(double,double)" (?calculateBasicVolume@@YAMNN@Z) referenced in function "int __cdecl ReadInputShapeChoice(void)" (?ReadInputShapeChoice@@YAHXZ)
1>task2.obj : error LNK2019: unresolved external symbol "void __cdecl printResult(void)" (?printResult@@YAXXZ) referenced in function "int __cdecl ReadInputShapeChoice(void)" (?ReadInputShapeChoice@@YAHXZ)
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>c:\users\pin\documents\visual studio 2012\Projects\Workshop13_task2\Debug\Workshop13_task2.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
First of all, when you post code, pleas use code tags to make it easier for us to read your code. They show us as "<>" in the Format box on the right of the text input box.

Next, it appears you don't quite understand how to use functions. Maybe you should read this tutorial before continuing.

http://cplusplus.com/doc/tutorial/functions/

You can also look at the"Declaring Functions" section at the end of this tutorial (the rest may be a bit advanced for you right now).

http://cplusplus.com/doc/tutorial/functions2/

Make sure of the following:
- When defining your functions, don't put a ';' between the"()" and the"{"
- Make sure each function definition ends with a "}"
- If your function is defined with a return value, make sure there is a return statement that actually returns the value.

I don't see a specific recursion in your code, but it's because of the other errors.
Hi thanks for your reply, I've taken a look through the tutorials you pointed out thank you for that.

I've tried to edit the code as required, and no recursion errors, but I still get an expected ';' on line 15 after the '()' and cant seem to figure out why, I thought it was because I had declared r and h inside the function, so I declared them outside but that doesnt work.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
using namespace std;
//function prtototypes
double ReadShapeDimensions(double,double);
float calculateBasicVolume(double,double);
void printResult();
int ReadInputShapeChoice(int){
	int choice;
	float volume;
	double r,h;
	cout<<"Volume calculator\n\nPlease select a shape:\n(1)Cylinder\n(2)Cone\n";
	cin>>choice;
	return choice;
	ReadShapeDimensions(r,h)
	{
			double r, h;
	cout<<"Please enter the radius of the shape\n";
	cin>>r;
	cout<<"Please enter the height/length of the shape\n";
	cin>>h;
	return r;
	return h;
	}
	calculateBasicVolume(r,h)
	{
		{
			if (choice=1){
			volume=3.14*r*r*h;
			return volume;
		}
		else if (choice=2)
		{
	
			volume=0.33*3.14*r*r*h;
			return volume;
		}
	}
	printResult(){
		cout<<"Volume = "<<volume<<"u^3";
	}
	
}
int main();{
ReadInputShapeChoice();

return 0;
}
	}
sorry, realised another mistake same problem applies

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
using namespace std;
//function prtototypes
void ReadShapeDimensions(double,double);
float calculateBasicVolume(double,double);
void printResult();
int ReadInputShapeChoice(int)
	{
	int choice;
	float volume;
	double r,h;
	cout<<"Volume calculator\n\nPlease select a shape:\n(1)Cylinder\n(2)Cone\n";
	cin>>choice;
	return choice;
	
	void ReadShapeDimensions(r,h)
	{
		double r,h;
		
	cout<<"Please enter the radius of the shape\n";
	cin>>r;
	cout<<"Please enter the height/length of the shape\n";
	cin>>h;
	return r;
	return h;
	}
	double calculateBasicVolume(r,h)
	{
		{
			if (choice=1){
			volume=3.14*r*r*h;
			return volume;
		}
		else if (choice=2)
		{
	
			volume=0.33*3.14*r*r*h;
			return volume;
		}
	}
	printResult(){
		cout<<"Volume = "<<volume<<"u^3";
	}
	}
}
	

int main();{
ReadInputShapeChoice();

return 0;
}

	
seems like if you got rid of some unnecessary returns and brackets and functions.. it might work. try this code
oh and some variables were declared twice.. I edited this post

#include <iostream>
using namespace std;

float ReadInputShapeChoice(){
int choice;
float volume;
double r,h;
cout<<"Volume calculator\n\nPlease select a shape:\n(1)Cylinder\n(2)Cone\n";
cin>>choice;
cout<<"Please enter the radius of the shape\n";
cin>>r;
cout<<"Please enter the height/length of the shape\n";
cin>>h;
if (choice=1){volume=3.14*r*r*h;}
else if (choice=2){volume=0.33*3.14*r*r*h;}
cout<<"Volume = "<<volume<<"u^3";
float num_to_return;
num to return = volume;
return num_to_return; // I know this bit is redundant
}
int main();{

float num_returned; // really, all this stuff w num_to_return is...
num_returned = ReadInputShapeChoice(); // ...not necessary

return 0;
}

now that should work lol i've tweaked it a few times
Last edited on
sorry i should have mentioned, we were given the function prototypes so we have to include them, otherwise i would have written something similar to that, thanks very much for your help though.
Last edited on
oh k.. you should know something about return;

when you return a variable from a function you need to assign the callback to the same kind of var.. like this:

#include <iostream>
using namespace std;

int sample_function(int base)
{
int multiple;
multiple = (base * 37);
return multiple;
}

int main()
{
int num_x, num_y;

cout << "Enter an integer: ";
cin >> num_x;

num_y = sample_function(num_x);
cout << "\nYou entered: " << num_x;
cout << "\n" << num_x << " x 37 = " << num_y;

return 0;
}

// see how I call "sample_function(int)"?

num_x is assigned a value with cin >>
then its value is passed to "sample_function(int)"
(it's called "base" within the function and changes to
it do not affect the original variable "num_x".. it has
been "passed by value" not by reference.)
the function then returns its local variable "multiple"
and assigns its value to "num_y"

hope this helps with your problem
Last edited on
It would appear that you're trying to put the definition of a functions inside the definition of another function.

You can't do that.

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
void ReadShapeDimensions(double,double);
float calculateBasicVolume(double,double);
void printResult();
int ReadInputShapeChoice(int);

void ReadInputShape(int) // why does this take an int if you're not using?
{
      // implementation goes here.
}

void printResult()
{
    cout<<"Volume = "<<volume<<"u^3";
}

float calculateBasicVolume(double r, double h)
{
    // implementation goes here.
}

void ReadShapeDimensions(double r, double h)
{
    // implementation goes here.
}

int main()
{
   // call functions here.
}
Last edited on
Topic archived. No new replies allowed.