3 Replies - 7724 Views - Last Post: 23 February 2009 - 07:46 PM Rate Topic: -----

#1 oskar132  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 23-February 09

cannot convert from 'double [300]' to 'double'

Posted 23 February 2009 - 05:35 PM

double romanoReal(char romano[])
{
	double numeroReal[300];
	double contador= 0;
	for(int i=0;i<300;i++)
{
	char comparar=romano[i];
	if(comparar =='x')
	{
	numeroReal[i]=100000;
	}
	
}
	return numeroReal; >>>> the error is here
}


the error is error C2440: 'return' : cannot convert from 'double [300]' to 'double'
i'm really new to c++ its the 2nd time i use it :S
don't know what im doing wrong plz heeeeeelp

Is This A Good Question/Topic? 0
  • +

Replies To: cannot convert from 'double [300]' to 'double'

#2 bobstock9  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 23-February 09

Re: cannot convert from 'double [300]' to 'double'

Posted 23 February 2009 - 06:05 PM

View Postoskar132, on 23 Feb, 2009 - 04:35 PM, said:

double romanoReal(char romano[])
{
	 the array;
	double contador= 0;
	for(int i=0;i<300;i++)
{
	char comparar=romano[i];
	if(comparar =='x')
	{
	numeroReal[i]=100000;
	}
	
}
	return numeroReal; >>>> the error is here
}


the error is error C2440: 'return' : cannot convert from 'double [300]' to 'double'
i'm really new to c++ its the 2nd time i use it :S
don't know what im doing wrong plz heeeeeelp



Hello,
You have declared the array "double numeroReal[300]".
The symbol numeroReal is of type "pointer to double".
But your function return value declares a return value of type "double".
One fix is: *double romanoReal(char romano[]) {}.

But you have a bigger problem: numeroReal is local to your function
(i.e. on the stack) and becomes undefined when the function returns.
You must declare numeroReal[] outside of the function, and pass the array
name into the function as a second parameter.

In short, you cannot return a local array, or a pointer to a local array.
The array must exist before calling your function. You must pass the
array name as a parameter - store your data - and just return (no
return value. So you have:
double numeroReal[300];
void romanoReal(char romano[], double numeroReal[] ) {};
Was This Post Helpful? 1
  • +
  • -

#3 oskar132  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 23-February 09

Re: cannot convert from 'double [300]' to 'double'

Posted 23 February 2009 - 06:40 PM


cout << "ingrese el primer valor de la suma\n\n";
		cin >> primerRomano; >>>the roman number i recieve
		romanoReal(primerRomano,numeroReal1);>> i take it and execute the method
		cout << numeroReal1; now i want to return the array i entered as a parameter and i added the int.

im running the program and im gettin  a 0012F380
what could it be :S?






 /////////////////////////////////////////////////////////////////
void romanoReal(char romano[], double numeroReal[] ) 

{
	
	double contador= 0;
	for(int i=0;i<300;i++)
{
	char comparar=romano[i];
	if(comparar =='x')
	{
	numeroReal[i]=10;
	}
	
}

} 

Was This Post Helpful? 0
  • +
  • -

#4 OrganizedChaos  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 153
  • Joined: 29-November 08

Re: cannot convert from 'double [300]' to 'double'

Posted 23 February 2009 - 07:46 PM

Arrays are always passed by reference. There's no need to return it.
Simply put a for loop in your main() that prints out every item of the array.
for(int i = 0; i < 300; i++)
   cout << "Array element " << i << ": " << numeroReal[i] << endl;


Hope this helps.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1