int sum1 (int ) // <- this int is the one you want to use, but you didn't give it a name
{
int n; // <- instead you are using this int, which you never assigned any value to
// so it will be random garbage
You probably meant to do this:
1 2 3
int sum1(int n) // <- n is the passed parameter
{
//int n; <- get rid of this
Also, you are never actually calling your sum1 function, so that code will never be executed anyway.
1 2 3 4
int n = 5;
int sumone; // <- this variable is never initialized
cout << "The value of sum1 is " << sumone << endl; // <- so what do you expect this to print?
You will need to actually call your function in order for the code inside it to be run. You want to assign whatever the function outputs to your sumone variable. That will look like this: