lab15hw-basic-arrays-soln - Remember we count from 0...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// Solution to Basic Arrays homework, from // http://php.scripts.psu.edu/djh300/cmpsc201/lab15hw-arraybasics.htm #include <iostream> using namespace std; int main() { double data[10]; // array to hold given numbers int loc; // location selected by user for // desired element data[0] = 5.1; // store the data data[1] = 3.2; data[2] = 9.4; data[3] = 10.7; data[4] = -0.3; data[5] = 1.75; data[6] = 2.1; data[7] = -5; data[8] = -22; data[9] = 17.1; // QUESTION 1
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Remember, we count from 0. cout << "First element: " << data[0] << endl; // QUESTION 2 cout << "Third element: " << data[2] << endl << endl; // QUESTION 3 cout << "Enter an index from 0 to 9 to get the element at that index: "; cin >> loc; cout << "Element at location " << loc << ": " << data[loc] << endl; // When you run your program, see what happens when you enter an // index that's out of range. return 0; }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online