vector output problem

hello everyone, I have encountered a problem using vectors. In this program I am trying to create a vector that contains degree values ranging from 0 to 90 in steps of 5 degrees. The degree function is used to assign the values to the vector but for an unknown reason the output only displays 0's. Help would be gladly apreciated =)




#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

void degree (vector<double> &arg, int length)
{
int degree = 0;
int n = 0;

while (n < length)
{
arg.push_back (degree);
n = n + 1;
degree = degree + 5;
}
}


void printarray (vector<double> arg, int length )
{

int n = 0;

while (n < length)
{
cout << arg.at(n) << " ";
n = n + 1.0;
}

cout << endl;
}



int main()
{
vector<double> degTheta(19);

degree (degTheta, 19.0);

printarray (degTheta,19.0);

return 0;

}
changing vector<double> degTheta(19); to vector<double> degTheta; fixes the problem aparently but i would like to understand why that is
closed account (zb0S216C)
sakilo wrote:
vector<double> degTheta(19);

..doesn't match any of std::vector's constructors. You're missing an argument:

std::vector<double> degTheta(19, 0.0);

The second argument is the initial value that all 19 doubles will be initialised to.

Wazzak
Last edited on
ahh that makes sense thank you =)
Topic archived. No new replies allowed.