filling array with a user input exit
Apr 19, 2014 at 4:05am UTC
Hi, I do not know how to exit my array with a user input value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void fillArray(double newThrust[Capacity][Cols], int & numOfElements){
double thrust;
cout << "\nEnter thrust curve data (0 for thrust to end list)" << endl;
for (int i = 0; i < Capacity; i++){
for (int j = 0; j < Cols; j++){
cin >> thrust;
newThrust[i][j] = thrust;
}
}
numOfElements++;
}
this is my function so far and do not know how to exit it using a "0". Please help.
Apr 19, 2014 at 4:21am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
void fillArray(double newThrust[Capacity][Cols], int & numOfElements) {
double thrust;
cout << "\nEnter thrust curve data (0 for thrust to end list)" << endl;
for (int i = 0; i < Capacity; i++){
for (int j = 0; j < Cols; j++){
cin >> thrust;
if ( std::abs(thrust) < 1.0e-6 ) goto done ; // break out of nested loop
newThrust[i][j] = thrust;
++numOfElements ;
}
}
// numOfElements++;
done:
}
Apr 19, 2014 at 4:38am UTC
Thank you very much. Can you please explain that if statement cause i have not seen that yet in my class.
Apr 19, 2014 at 5:58am UTC
Floating point numbers are inexact representations of real numbers. Though a comparison with zero (
== 0.0
) would usually work as expected, as a general programming technique, one should avoid exact comparisons of floating point numbers.
http://www.parashift.com/c++-faq/floating-point-arith.html
Apr 20, 2014 at 1:33am UTC
i have a new request. with the exit being 0 i also need to input that zero into that last array column. right now its a crazy number.
Apr 20, 2014 at 2:24am UTC
nevermind i figured out a way i can do it without that number being zero.
Topic archived. No new replies allowed.