C/C++ C++ Vector Resize: Counting Down to the Test

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    C++ Vector
AI Thread Summary
To create a countdown vector with elements from newSize down to 1, the vector must first be resized using countDown.resize(newSize). After resizing, the vector needs to be populated with integers in descending order. The code snippet provided indicates that the user attempted to resize the vector but did not populate it correctly, leading to confusion. The key takeaway is that resizing alone is insufficient; the vector must also be filled with the appropriate values for the desired output of "3 2 1 Go!".
ineedhelpnow
Messages
649
Reaction score
0
going through problems to study for a test

Resize vector countDown to have newSize elements. Populate the vector with integers newSize down to 1. Ex: If newSize = 3, then countDown = {3, 2, 1}, and the sample program outputs:

3 2 1 Go!
Sample program:

Code:
#include <iostream>
#include <vector>
using namespace std;

int main() {
   vector<int> countDown(0); 
   int newSize = 0;             
   int i = 0;                         

   newSize = 3;
   <STUDENT CODE>

   for (i = 0; i < newSize; ++i) {
      cout << countDown.at(i) << " ";
   }
   cout << "Go!" << endl;

   return 0;
}

i tried countDown.resize(newSize); but it didnt work.
 
Technology news on Phys.org
ineedhelpnow said:
i tried countDown.resize(newSize); but it didnt work.

Hi! ;)

That should work to resize the vector.
But I think you still have to populate the vector in order to get 3, 2, 1. (Thinking)
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
Back
Top