The variable 'F' is being used without being initialized.help!?

The variable 'F' is being used without being initialized.help!?

this is the program i am trying to write.
it has no aparant problem except the error stated above about the third line from the bottom.
i have initalized F in the for loop and it printed it out fine.
what is my problem?!?!
please heeelp
p.s.i can't use an int in the for loop becasue exp needs a double!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
 
#include <iostream>
 #include <conio.h>
 #include <math.h>
 using namespace std;
 
int main()
 { int n,l,k;
 double a,b,f,f1,g,i,h;
 
 double F[100];

 cout <<" This program calculates the integral of e^x by using a variation of the simpson rule."<< endl;
 cout<< "Please entet the integral's lower bond:"<< endl;
 cin>> a;
 cout<< "Enter the integral's upper bond:"<< endl;
 cin>> b;
 cout << "Enter the desired number of partitions:" << endl;
 cin>> n;
 cout<< "The length of each partiton is:"<<endl;
 h=(a+b)/n;
 cout<< h << endl;

 for (i=a; i<=b; i=i+h)
 { f=exp(i);
 F[k]=f;

 cout<< F[k]<<endl;}


 cout<< F[0];
 
getch();
 return 0;
 }
I tried your code at www.ideone.com removing before executing header <conio.h> and function getch and the code was executed successfuly.
what is the value of k? you haven't initialized it. Also, F[0] does not contain anything.

You can initialize all the array elements to zero by
 
double F[100] = {};
The variable k is not initialised?
Topic archived. No new replies allowed.