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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akashranjan
    New Member
    • Sep 2021
    • 1

    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)) ===|
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    Code:
    #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)) ===|
    Probably meant to be this
    Code:
    sum=n*(n+1)/2;
    ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎

    Comment

    Working...