Hi guys, would appreciate your help since Im beginner everything in this fantastic language seems wired for me. I got the follwing codes:
1.
//The function SumTo() takes an integer and prints out the sum of all integers upto that int.
Code:int SumTo(int nValue) { using namespace std; cout<<"enter the number: "; cin>>nValue; int nsum=0; for(int iii=0;iii<=nValue;iii++) nsum+=iii; return nsum; } int main() { using namespace std; cout<<SumTo(int nValue)<<endl; //This way of calling the function SumTo doesnt //work,why? return 0; }
2. If I on the otherhand declare my integer inside the SumTo() function then it works, as the code bellow.
Would be thankful for some help, how can I modify the first one to work?Code:int SumTo() { using namespace std; cout<<"enter the number: "; int nValue; cin>>nValue; int nsum=0; for(int iii=0;iii<=nValue;iii++) nsum+=iii; return nsum; } int main() { using namespace std; cout<<SumTo()<<endl; return 0; }



LinkBack URL
About LinkBacks



