Here is the code:
#include <cstdlib>
#include <iostream>
using namespace std;
//Declare function
int triangle(int num);
int main() {
int n;
cout<<"Enter a number and press RETURN: ";
cin>> n;
cout<<"Function returned:"<<triangle(n)<<endl;
return 0;
}
//define function
int triangle(int n){
int i;
int sum=0;
for(i=1; i<=n; i++)
sum=sum+i;
return sum;
}
What my question is, why does this work if it's declared as
triangle(int num)
but defined as
triangle(int n)
I thought they had to be the same? When I put this in one compiler it works and in another I get an error? Can someone explain this to me please?