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 &lt;&lt; &quot;First element: &quot; &lt;&lt; data[0] &lt;&lt; endl; // QUESTION 2 cout &lt;&lt; &quot;Third element: &quot; &lt;&lt; data[2] &lt;&lt; endl &lt;&lt; endl; // QUESTION 3 cout &lt;&lt; &quot;Enter an index from 0 to 9 to get the element at that index: &quot;; cin &gt;&gt; loc; cout &lt;&lt; &quot;Element at location &quot; &lt;&lt; loc &lt;&lt; &quot;: &quot; &lt;&lt; data[loc] &lt;&lt; endl; // When you run your program, see what happens when you enter an // index that's out of range. return 0; }...
View Full Document

Ask a homework question - tutors are online