Hello just finished re- reading chapter 3...about functions... I learnt more of this from reading it when i was at home than when im at uni! Amazing!!

However I get a compile error saying

'not all control paths return a value'

heres the code:

#include <iostream>

using namespace std;

int test(int);
int ha(int);

int main()
{

int y;
cin >> y;

cout << "This is now going through the functions \n\n\n" << test(y);

return 0;

}

int test (int x)
{
int a;
int b;

	cout << "please enter a";
	cin >> a;
	cin >> b;

		if (a == 1)
			{
			cout << "now returning a";
	return a;	
			}

		else if ( a < 4)
			{
			cout << "function call to b" << ha(b);

			}

}

int ha(int c) 
{

	return c*c;

}

ok it doesnt make much sence but it was mocked up with what i learnt from the text book ... Please don't give me the answer hints would be most appricated ... :D

ok i re read that and it isnt clear...here is something a little more clearer!

#include <iostream>

using namespace std;

int proto(int, int);
int proto2(int);

int main()
{
	int x = 2;
	int z = 4;

cout << "this is the value of x when x is passed to proto " << proto( x, x )<<'\t'<<endl;
	return 0;
}

int proto(int y ,int c)
{




return y*y;
return c;
}

int proto2(int z)
{

return z*z;

}

just wondering if i can get proto2 to go through proto then proto passes that value to main?

>'not all control paths return a value'

if (a == 1) 
  { 
    cout << "now returning a"; 
    return a;     
  } 
  else if ( a < 4) 
  { 
    cout << "function call to b" << ha(b); 
  } 
}

If a is 1 then you return a, but if a is not 1, what do you return?

>just wondering if i can get proto2 to go through proto then proto passes that value to main?
That's not clear at all. Try again.

just wondering if i can get proto2 to go through proto then proto passes that value to main?

What about calling proto in proto2........

or possably re-writing proto 2 to take all the parameters like so

int proto2(int a, int b, int c) // proto 1 parameters also
{
  ... code for proto2 function (use c)

  int result = proto1(a, b)
  return result;
}

usage: int v = proto2(y, c, z);

This article has been dead for over six months. Start a new discussion instead.