mardi 29 octobre 2019

How to determine number of values added to vector in C++?

I'm trying to build a little task using C++ in which I need to allow the user to determine up front how many gross_paychecks they would like to place in a vector called 'gross_paychecks_vector'.

So far this is what I have:

vector<double> gross_paychecks_vector (5);
  double gross_paychecks;
  // Add 5 doubles to vector
  cout << "Please enter an integer" << endl;
  cin >> gross_paychecks;
  for(gross_paychecks = 0; gross_paychecks <= gross_paychecks_vector; ++gross_paychecks ){
    cin >> gross_paychecks;
  }

Right now I'm somewhat lost because I'm not sure whether to switch the vector to something like vector<double> gross_paychecks {} because it trows me an error in the for loop.

Also I'm not sure how to go with the for loop(should I actually use a for-loop or something else?). I need to accept input from the user as long as it has not met the numbers of gross_paychecks that he/she has specified.

Aucun commentaire:

Enregistrer un commentaire