So, I am in the mid part of my C++ class and am having trouble with a vector project at the end of the chapter. I don't expect the answer, but if someone would point me in the right direction I would greatly appreciate it :)
#1). Write a loop that will print the values in a 20 element vector named quantity to the screen.
(When I compile the code it increments by 10 for the 20 values and I'm pretty sure this isn't correct)
#2). Write a loop that will initialize the values in a 100 element vector of type double, named x with the loops index value. For example, the element at subscript 0 should have a value of 0, and the value at subscript 11 should have a value of 11.
(When I compile the code it doesn't give me any values, just "0").
Here is my code:
// vector.cpp Project 9-1 pg. 232
#include <iostream>
#include <vector>
using namespace std;
vector <long> LongVector; // These 3 vectors are just step 1 of the project. Please ignore.
vector <float> n (10);
vector <int> z (100, 0);
int main()
{
// loop that prints 20 values
vector <double> quantity (20);
for (int index = 0; index < 20; index++)
{
cout << "Value " << index << quantity [index] << ": " << endl;
}
cout << endl << endl; // added this for neatness :)
// loop that prints 100 elements
vector <double> x (100);
for (double index = 0; index < 100; index++)
{
cout << "Element " << index + 1 << ": " << x [index] << endl;
}
return 0;
}