How do I store different numbers into a array and than compare them later on. The variable I'm trying to store is y.

#include <iostream>
#include <cmath>
#include <vector>


using namespace std;


double income (double a, double b, double I) {
double i;
i = I/100;
double r;
double x;
double y;
r = a*(i * pow(1+i, b-1));
x = (pow(1+i, b) - 1);
y = r / x;
return y;


}


int main() {
double X, N, I;
double y;
double s = 0;
double avg;
int t;
double great[t];
double d = 0;
double r;


while(X > -1 || N > -1 || I > -1) {

cout << "Enter values for X, N, and I: " << endl;
cin >> X >> N >> I;

if(X>=0 && N >= 5 && I> 0 && I<= 10) {
y = income (X, N, I);
d = d + y;
s = s + 1;
cout << d << endl;
}

else if (X == -1 && N == -1 && I == -1) {
avg = d / s;
cout << "Avg: " << avg << endl;
cout << "Please enter the income" << endl;
for(t = 0; t<=5; t++) {
cin >> great[t];

cout << great[t] << endl;
}

}

else {

cout << "re-try" << endl;

}




}

return 0;

}
int t;
double great[t];
variables cant be used for array sizes in standard c++. even if this is allowed by a nonstandard compiler, using an uninitialized variable is going to give poor results.

consider vector. it can grow to fit.

however the basic idea is
double g[100000]; //suitably large size for the problem, pick your value.
int current = 0;
...
for()
g[current++] = y; //stores every y computed in the loop in the next location.
...
other code;
use(g[index]); //use it later.

or, again, look at
vector<double> g;
..
g.push_back(y); //vector version of above
g[index] //use it later etc
Last edited on
Topic archived. No new replies allowed.