So I was trying to pull a value from array num and use it in the function int addition and I think I have some punctuation errors, anyone want to further elaborate??
int addition ( int a, int b);
{ int a;
int b;
//array stated here
int num [5]= {5,10,15,20,25};
//Giving the value in 3rd block of array (20) to variable "a" stated here. Same thing with int b
a= num[3];
b= num[4];
int r;
r=a+b;
return (r);
}
int main ();
{
int z;
z = addition (a,b);
cout<<"this equals"<< z;
return 0;
}
Your code won't compile as it stands.
There is a semicolon which should be removed from the first line of the definition of both main() and addition().
-- remove the semicolon from lines 1 and 14 above.
Function addition has 2 integer parameters. However, at lines 2 and 3, new local variables called a and b are defined. These should be removed.
The call of addition() at line 17 above tries to pass a and b which do not exist within the scope of main().
Here's an example of your code modified so it will compile (though it doesn't make very much sense).
#include <iostream>
usingnamespace std;
int addition ( int a, int b)
{
//array stated here
int num [5]= {5,10,15,20,25};
//Giving the value in 3rd block of array (20) to variable "a" stated here. Same thing with int b
a= num[3];
b= num[4];
int r;
r=a+b;
return (r);
}
//--------------------------------
int main ()
{
int z;
z = addition (22, 7);
cout << "this equals" << z;
return 0;
}
Note, no matter what values of a and b are passed to the function, the return value r will always equal 45.
#include <iostream>
usingnamespace std;
int addition ( int a, int b) {
int c=a+b;
return (c);}
int main () {
int z=addition (3,5);
cout << "result: " << z << endl;
return 0; }