# Error: Function fill\_graph(n,x,y,ex,ey,2) is not defined in current scope

**URL:** <https://root-forum.cern.ch/t/error-function-fill-graph-n-x-y-ex-ey-2-is-not-defined-in-current-scope/48511>\
**Category:** Newbie\
**Created:** [January 23, 2022, 3:23pm UTC](https://root-forum.cern.ch/t/error-function-fill-graph-n-x-y-ex-ey-2-is-not-defined-in-current-scope/48511 "2022-01-23T15:23:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![acgc99](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/a9a28c/32.png) [@acgc99](https://root-forum.cern.ch/u/acgc99)\
**Post date:** [January 23, 2022, 3:23pm UTC](https://root-forum.cern.ch/t/error-function-fill-graph-n-x-y-ex-ey-2-is-not-defined-in-current-scope/48511/1 "2022-01-23T15:23:55Z")

</div>

Hi!  
I’m new to C++ and ROOT (but not to programing (python)). I’m trying to create a function to fill a TGraphErrors, but I get the following error.

```auto
Processing C:\Users\acgc9\Desktop\CorrientesDeFuga.c...
Warning: Automatic variable i is allocated C:\Users\acgc9\Desktop\CorrientesDeFuga.c(26)
Error: Function fill_graph(n,x,y,ex,ey,2) is not defined in current scope C:\Users\acgc9\Desktop\CorrientesDeFuga.c(30)
***Interpreter error recovered***

```

Here is the code:

```auto
/* Funtions declaration */

TGraphErrors fill_graph(Int_t n, Double_t x, Double_t y, Double_t ex, Double_t ey, Int_t index);

void CorrientesDeFuga() //main
{
	
	const Int_t n = 6;
	
	Double_t x[n] = {10, 20, 30, 40, 50, 60};
	Double_t y[n] = {10, 20, 30, 40, 50, 60};
	
	Double_t ex[n] = {0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
	Double_t ey[n] = {1, 1, 1, 1, 1, 1};
	
	TCanvas* c1 = new TCanvas("c1", "test", 640, 480);
	TMultiGraph* mg = new TMultiGraph();

	
	TGraphErrors* gr = new TGraphErrors(n, x, y, ex, ey);	
	gr -> SetMarkerStyle(1);
	gr -> SetMarkerColor(1);
	gr -> SetLineColor(1);
	mg -> Add(gr);
	
	for (i=0; i<n+1;++i)
	{
		y[i] = 2*y[i];
	}
	
	TGraphErrors* gr1 = fill_graph(n, x, y, ex, ey, 2);
	mg -> Add(gr1);
	
	mg -> Draw("ap");

	
}

TGraphErrors fill_graph(Int_t n, Double_t x, Double_t y, Double_t ex, Double_t ey, Int_t index)
{
	TGraphErrors* graph = new TGraphErrors(n, x, y, ex, ey);
	
	graph -> SetMarkerStyle(1);
	graph -> SetMarkerStyle(1);
	graph -> SetMarkerColor(index);
	
	return graph;
}

```

Thanks!

_ROOT Version:_ 5.34/38  
_Platform:_ Windows 11  
_Compiler:_ CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 23, 2022, 3:49pm UTC](https://root-forum.cern.ch/t/error-function-fill-graph-n-x-y-ex-ey-2-is-not-defined-in-current-scope/48511/2 "2022-01-23T15:49:06Z")

</div>

`TGraphErrors *fill_graph(Int_t n, Double_t *x, Double_t *y, Double_t *ex, Double_t *ey, Int_t index)`

`for (Int_t i = 0; i < n; i++)`
