BASIC HELP

how would i call the variable within the parameter to perform a loop or if statement within the void function


void police(int&year, int & crimes, int&arrests, int& thefts, int&assts, int&robberies, int&homicides)
{

file>>year;

}
first of all, i would not recommend using pointers in parameters, to prevent from changing the base variable, unless you have too.

second of all, when you make a parameter you declare a variable. when you call a function you would enter a variable as a parameter, when this happens the parameter that corresponds will equal that value. for example, if you have a function like this:

void foo(int bar,int yes){}

and you call it like this:

foo(1337, 1234);

now bar = 1337 and yes = 1234

to use these values in the function you would need to call them in the function. like so:

1
2
3
4
5
6
7
8
9
10
11
void foo(int bar, int yes)
{
     if(bar == 1337)
     {
          cout << "bar is 1337" << endl;
     }
     while(yes == 1234)
     {
          cout << "Looping all day!" << endl;
     }
}


call it like so:

foo(1337,1234);

output:

bar is 1337
Looping all day!....


hope this helps!
Thank you!
Topic archived. No new replies allowed.