Integrating using c++

I have this program to integrate a polynomial. The user has to enter 6 integers.

Here's what I have so far:


#include <iostream>
using namespace std;

void Int_poly(float& a, float& b, float& c, float& d, float& e, float& f);

int main ()
{
float v[0], v[1], v[2], v[3], v[4], v[5];
float i=0;
char try_again;

do
{
cout<<"\nEnter six integers:";
cin>>v[0]>>v[1]>>v[2]>>v[3]>>v[4]>>v[5];
}


while(try_again=='y'||try_again=='Y');
cout<<"\nDo you want to try again! (y/n):";

cin>>try_again;

cout<<"\nBye!\n";
return 0;
}

void Int_poly(float& a, float& b, float& c, float& d, float& e, float& f)
{
for(i=0;i<=v[5];i--){
if(i==0)
{
cout<<"The integration is \n"<<;
}}

}

I would really appreciate some help. Thanks in advance.
1. Use code tags.

2. You declare an array by specifying the size in the declaration of the array just once, like this:
float v[5]

All 6 indices of the array will be created. You don't have to declare each index separately.

3. Your while loop isn't going to work. try_again is uninitialized when you evaluate the while clause, so it's just going to fall through on the first check. You need to move your prompt to try again inside the body of the loop.

4. Since your ints are all stored in an array, just pass that array to the function. No need to declare each value as a separate parameter.

5. You are prompting for integers, but storing them in floats. Don't know if that's intentional or not.
I am prompting the user to enter six numbers, or integers...whether the entrys are negative or positive. Is this what you meant?


#include <iostream>
using namespace std;

void Int_poly(float& a, float& b, float& c, float& d, float& e, float& f);

int main ()
{
float v[5];
float i=0;
char try_again;

do
{
cout<<"\nEnter six integers:";
cin>>v[0]>>v[1]>>v[2]>>v[3]>>v[4]>>v[5];
}

cout<<"\nDo you want to try again! (y/n):";
cin>>try_again;
while(try_again=='y'||try_again=='Y');


cout<<"\nBye!\n";
return 0;
}

void Int_poly(float v[5])
{
for(i=0;i<=v[5];i--){
if(i==0)
{
cout<<"The integration is \n"<<;
}}

}

I'n not sure how I should set up the formula, etc. I'm very new to this and I need so much help. Thanks for everything.
When you declare an array, you say you only want 5 elements, but try to access a 6th with v[5]. I assume you meant int v[6];

You're having trouble with the formula? Do you know how to integrate a polynomial on paper? Just write code trying to implement that.
And you're still not using code tags. When you make a post, there is a little hash button on the right side, under "Format:". Click that, and put your code between the code tags that appear.
As I said before, I am not sure what to do, nor do I know what you are talking about. SHOW me what you are talking about in the program.

The program has to output the integration of the 6 inputs.
 
float v[5];



I am prompting the user to enter six numbers, or integers.


Yes, you are prompting them to enter 6 integers, but you are accepting 6 floating point numbers.

1
2
3
float v[5];  // Allocates an array whose valid indices are 0..4 inclusive (5 total elements)

cin >> /* ... */ v[ 5 ];   // 5 is not a valid index per previous comment 



Topic archived. No new replies allowed.