My compiler is showing the error: 'y' was not declared in this scope.
I can't seem to find the source. I also can't seem to find anyone else with a similar problem. Soooooo I'm here! Here's my code.
#include <iostream>
usingnamespace std;
int factorial(int y);
int n, x;
int main()
{
cout << "Put in a number and I will show you it's factorial starting from 1." << endl;
cin >> n;
for(int i=1; i<=n; i++)
{
if(i==n)
{
cout << i << " = ";
break;
}
cout << i << " * " << factorial(y);
}
return 0;
}
int factorial(int y)
{
for( x = 1; x <= n; x++)
{
y=x*(x+1);
}
if(x==n)
{
return y;
}
}
I don't think you looked at either of those links if you are asking me what I meant... here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
void print(int x) //x is a local variable with a value that is passed to function
{
std::cout << x << std::endl;
}
int main()
{
int a = 10;
print(a); //a is passed with a value of 10. So x is initialized to 10
print(20); //20 is passed so x is initialized to 20
return 0;
}