Your code is messed up. If you want to let the user enter the size of an array, then you need to allocate it in the heap otherwise the size of an array must be const. Second, double ai; you declared it as a double not an array, so you need to alter it. cin>>ai[n]; ??????

There are a great deal of fundamental errors here. I think you need to reread how to use:
-Declaring variables
-Arrays
-functions

In that order. Then rewrite this program from scratch.

I could address each error in your code blow by blow here, but I think you will find it to be of more benefit to reread the stuff. I suspect there will be other things fundamentally wrong other than what we see here.