I am trying to figure out the best way to create a dynamic array/vector (not sure which) that would take in a string and double and store it. I then need to print the string with the corresponding double into a list and produce a total for all the doubles that were entered. I am lost as to how I set up my header and source file so that I can accomplish this. I am using C++ How to Program by Deitel, I have read through chapter 7 (arrays and vectors) and chapter 22 (STL on vectors) but I am still lost on how to begin this. I know I will need to loop the vector with a while loop so that if the user enters 0 or NULL it will terminate for prompting the user to enter in a string and a double. If someone could help by providing me an example of what this should be set up like I would greatly appreciate it. I need to use this to create a list of stocks and amounts so I am not looking for anyone to do my homework. But I just want to see how a vector can be used to take in a string and a double and later retrieve it for outputting a list and a total. Thanks in advance.
Tech E
1
Newbie Poster
Recommended Answers
Jump to PostCreate a structure (or a class) that contains your string and double and then make a vector of those.
You can use a normal loop or one of the stl algorithms to perform operations on it.
All 3 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.