469,342 Members | 6,008 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

error: 'n' cannot be used as a function| || c++

#include<bits/stdc++.h>
using namespace std;

int main()
{
int n,sum;
cout<<"enter the number to find the sum upto that :";
cin>>n;

sum=n(n+1)/2;

cout<<"the sum of all natural number upto "<<n<<"is :"<<sum;

}


How to resolve Error I'm getting below:


|error: 'n' cannot be used as a function|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
Sep 16 '21 #1
1 3461
dev7060
507 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n,sum;
  7. cout<<"enter the number to find the sum upto that :";
  8. cin>>n;
  9.  
  10. sum=n(n+1)/2;
  11.  
  12. cout<<"the sum of all natural number upto "<<n<<"is :"<<sum;
  13.  
  14. }

How to resolve Error I'm getting below:


|error: 'n' cannot be used as a function|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
Probably meant to be this
Expand|Select|Wrap|Line Numbers
  1. sum=n*(n+1)/2;
‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎
Sep 18 '21 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Sorisio, Chris | last post: by
2 posts views Thread by =?Utf-8?B?S3Jpc2huYQ==?= | last post: by
2 posts views Thread by srilathaapi | last post: by
2 posts views Thread by sam.barker0 | last post: by
5 posts views Thread by Just Another Victim of the Ambient Morality | last post: by
1 post views Thread by Alberto Menchen | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.