0
    #include <iostream>
    using namespace std;
    float n;
    float fact(float m)
    {
    float prod=1;
    while(m>1)
     { 
      prod*=m;
      m--;
     }
    return prod;
    }
    ////////////////////////////////
    float min(float b[],float n)
    { float small=999999999999;
    for(float f=0;f<n;f++)
        if(b[f]<small)
            small=b[f];
    return small;
    }
    /////////////////////////////////
    float max(float a[],float n)
    { float small=-999999999999;
       for(float i=0;i<n;i++)
        if(a[i]>small)
            small=a[i];
      return small;
    }
    //////////////////////////////////////
    float sum(float a[],float n)
    {float sum=0;
    for(float i=0;i<n;++i)
    sum+=a[i];
    return sum;
    }

    int main() {
    float t,q2,count=0;

        scanf("%d",t);
    float *n=new float[t];
    float *m=new float[t];
    float *q=new float[t];
    float *k=new float[t];
    for(float p=0;p<t;++p)
    {cin>>n[i]>>m[i]>>q[i]>>k[i];}
    for(float p=0;p<t;++p)
    {   
    float *a=new float[n[p]];

    for(float i=0;i<n[p];++i)
     a[i]=i+1;

    for(float i=n[p];i<=m[p];++i)
    {a[n[p]-1]=n[p];

    for(float i=0;i<k[p];++i)
    {
    for(float i=0;i<n[p];++i)
    a[i]=min(a,n[p])+sum(a,n[p])-a[i];//important
    }

    q2=max(a,n[p])-min(a,n[p]);
    if(q2==q[p])
    {count++;
    }
    }
    cout<<count*fact(n,n[p]);

    }   return 0;
    }

Can you please tell me my mistakes? Following errors noted! I think if solved any one , it will help throughout

        prog.cpp:16: error: integer constant is too large for 'long' type
        prog.cpp:24: error: integer constant is too large for 'long' type
        prog.cpp: In function 'float min(float*, float)':
        prog.cpp:18: error: invalid types 'float*[float]' for array subscript
        prog.cpp:19: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'float max(float*, float)':
        prog.cpp:26: error: invalid types 'float*[float]' for array subscript
        prog.cpp:27: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'float sum(float*, float)':
        prog.cpp:34: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'int main()':
        prog.cpp:42: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:43: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:44: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:45: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:47: error: 'i' was not declared in this scope
        prog.cpp:50: error: invalid types 'float*[float]' for array subscript
        prog.cpp:52: error: invalid types 'float*[float]' for array subscript
        prog.cpp:53: error: invalid types 'float*[float]' for array subscript
        prog.cpp:55: error: invalid types 'float*[float]' for array subscript
        prog.cpp:55: error: invalid types 'float*[float]' for array subscript
        prog.cpp:56: error: invalid types 'float*[float]' for array subscript
        prog.cpp:56: error: invalid types 'float*[float]' for array subscript
        prog.cpp:58: error: invalid types 'float*[float]' for array subscript
        prog.cpp:60: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:64: error: invalid types 'float*[float]' for array subscript
        prog.cpp:64: error: invalid types 'float*[float]' for array subscript
        prog.cpp:65: error: invalid types 'float*[float]' for array subscript
        prog.cpp:69: error: invalid types 'float*[float]' for array subscript

        Compilation error    time: 0 memory: 0 signal:0
        prog.cpp:16: error: integer constant is too large for 'long' type
        prog.cpp:24: error: integer constant is too large for 'long' type
        prog.cpp: In function 'float min(float*, float)':
        prog.cpp:18: error: invalid types 'float*[float]' for array subscript
        prog.cpp:19: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'float max(float*, float)':
        prog.cpp:26: error: invalid types 'float*[float]' for array subscript
        prog.cpp:27: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'float sum(float*, float)':
        prog.cpp:34: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'int main()':
        prog.cpp:42: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:43: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:44: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:45: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:47: error: 'i' was not declared in this scope
        prog.cpp:50: error: invalid types 'float*[float]' for array subscript
        prog.cpp:52: error: invalid types 'float*[float]' for array subscript
        prog.cpp:53: error: invalid types 'float*[float]' for array subscript
        prog.cpp:55: error: invalid types 'float*[float]' for array subscript
        prog.cpp:55: error: invalid types 'float*[float]' for array subscript
        prog.cpp:56: error: invalid types 'float*[float]' for array subscript
        prog.cpp:56: error: invalid types 'float*[float]' for array subscript
        prog.cpp:58: error: invalid types 'float*[float]' for array subscript
        prog.cpp:60: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:64: error: invalid types 'float*[float]' for array subscript
        prog.cpp:64: error: invalid types 'float*[float]' for array subscript
        prog.cpp:65: error: invalid types 'float*[float]' for array subscript
        prog.cpp:69: error: invalid types 'float*[float]' for array subscript

        Compilation error    time: 0 memory: 0 signal:0
        prog.cpp:16: error: integer constant is too large for 'long' type
        prog.cpp:24: error: integer constant is too large for 'long' type
        prog.cpp: In function 'float min(float*, float)':
        prog.cpp:18: error: invalid types 'float*[float]' for array subscript
        prog.cpp:19: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'float max(float*, float)':
        prog.cpp:26: error: invalid types 'float*[float]' for array subscript
        prog.cpp:27: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'float sum(float*, float)':
        prog.cpp:34: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'int main()':
        prog.cpp:42: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:43: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:44: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:45: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:47: error: 'i' was not declared in this scope
        prog.cpp:50: error: invalid types 'float*[float]' for array subscript
        prog.cpp:52: error: invalid types 'float*[float]' for array subscript
        prog.cpp:53: error: invalid types 'float*[float]' for array subscript
        prog.cpp:55: error: invalid types 'float*[float]' for array subscript
        prog.cpp:55: error: invalid types 'float*[float]' for array subscript
        prog.cpp:56: error: invalid types 'float*[float]' for array subscript
        prog.cpp:56: error: invalid types 'float*[float]' for array subscript
        prog.cpp:58: error: invalid types 'float*[float]' for array subscript
        prog.cpp:60: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:61: error: invalid types 'float*[float]' for array subscript
        prog.cpp:64: error: invalid types 'float*[float]' for array subscript
        prog.cpp:64: error: invalid types 'float*[float]' for array subscript
        prog.cpp:65: error: invalid types 'float*[float]' for array subscript
        prog.cpp:69: error: invalid types 'float*[float]' for array subscript

        Compilation error    time: 0 memory: 0 signal:0
        prog.cpp:15: error: integer constant is too large for 'long' type
        prog.cpp:22: error: integer constant is too large for 'long' type
        prog.cpp: In function 'float min(float*, float)':
        prog.cpp:17: error: invalid types 'float*[float]' for array subscript
        prog.cpp:18: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'float max(float*, float)':
        prog.cpp:24: error: invalid types 'float*[float]' for array subscript
        prog.cpp:25: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'float sum(float*, float)':
        prog.cpp:32: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'int main()':
        prog.cpp:40: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:41: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:42: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:43: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:45: error: 'i' was not declared in this scope
        prog.cpp:48: error: invalid types 'float*[float]' for array subscript
        prog.cpp:50: error: invalid types 'float*[float]' for array subscript
        prog.cpp:51: error: invalid types 'float*[float]' for array subscript
        prog.cpp:53: error: invalid types 'float*[float]' for array subscript
        prog.cpp:53: error: invalid types 'float*[float]' for array subscript
        prog.cpp:54: error: invalid types 'float*[float]' for array subscript
        prog.cpp:54: error: invalid types 'float*[float]' for array subscript
        prog.cpp:56: error: invalid types 'float*[float]' for array subscript
        prog.cpp:58: error: invalid types 'float*[float]' for array subscript
        prog.cpp:59: error: invalid types 'float*[float]' for array subscript
        prog.cpp:59: error: invalid types 'float*[float]' for array subscript
        prog.cpp:59: error: invalid types 'float*[float]' for array subscript
        prog.cpp:59: error: invalid types 'float*[float]' for array subscript
        prog.cpp:62: error: invalid types 'float*[float]' for array subscript
        prog.cpp:62: error: invalid types 'float*[float]' for array subscript
        prog.cpp:63: error: invalid types 'float*[float]' for array subscript
        prog.cpp:67: error: invalid types 'float*[float]' for array subscript

        Compilation error    time: 0 memory: 0 signal:0
        prog.cpp:15: error: integer constant is too large for 'long' type
        prog.cpp:22: error: integer constant is too large for 'long' type
        prog.cpp: In function 'float min(float*, float)':
        prog.cpp:17: error: invalid types 'float*[float]' for array subscript
        prog.cpp:18: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'float max(float*, float)':
        prog.cpp:24: error: invalid types 'float*[float]' for array subscript
        prog.cpp:25: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'float sum(float*, float)':
        prog.cpp:32: error: invalid types 'float*[float]' for array subscript
        prog.cpp: In function 'int main()':
        prog.cpp:40: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:41: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:42: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:43: error: expression in new-declarator must have integral or enumeration type
        prog.cpp:45: error: 'i' was not declared in this scope
        prog.cpp:48: error: invalid types 'float*[float]' for array subscript
        prog.cpp:50: error: invalid types 'float*[float]' for array subscript
        prog.cpp:51: error: invalid types 'float*[float]' for array subscript
        prog.cpp:53: error: invalid types 'float*[float]' for array subscript
        prog.cpp:53: error: invalid types 'float*[float]' for array subscript
        prog.cpp:54: error: invalid types 'float*[float]' for array subscript
        prog.cpp:54: error: invalid types 'float*[float]' for array subscript
        prog.cpp:56: error: invalid types 'float*[float]' for array subscript
        prog.cpp:58: error: invalid types 'float*[float]' for array subscript
        prog.cpp:59: error: invalid types 'float*[float]' for array subscript
        prog.cpp:59: error: invalid types 'float*[float]' for array subscript
        prog.cpp:59: error: invalid types 'float*[float]' for array subscript
        prog.cpp:59: error: invalid types 'float*[float]' for array subscript
        prog.cpp:62: error: invalid types 'float*[float]' for array subscript
        prog.cpp:62: error: invalid types 'float*[float]' for array subscript
        prog.cpp:63: error: invalid operands of types 'float' and 'float*' to binary 'operator=='
        prog.cpp:67: error: invalid types 'float*[float]' for array subscript

1 Answer 1

3
  1. You cannot use a float in an array subscript (the part within the square brackets). Try using an int instead.

  2. scanf takes a pointer as its second (and subsequent) arguments. Replace scanf("%d", t) with scanf("%d",&t). Better still, use cin >> t, since you're using C++.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.