| Amishsuchak (3) | |
|
Hi guys, I have a task where I have to ask a user to enter a number between 1-10 and I have to ask if he wants to enter another number (Y for yes, N for no) , if its yes, The user keeps entering numbers. When the user says N, then I have to ask the user to enter a set of numbers of the same amount of the last numbers. Once that is done, I have to multiply each number of the new set with the corresponding value of the old set. So for example, (1st number of set A * first number of set B) etc and display the result of each multiplication. What I thought of was to add an if Y then cin>>a (which is an int) , but the problem is that there can be infinite amount of these variables, so I don't really know where to store them, if anyone has any ideas or tips on what to do, I would be really appreciated. | |
|
|
|
| Need4Sleep (532) | |||
is this a homework assignment? If not then i would use a vector / linked stack to hold each variable.
| |||
|
|
|||
| Disch (8349) | |||
|
vector: http://cplusplus.com/reference/stl/vector/ A vector is basically a resizable array:
| |||
|
|
|||
| Amishsuchak (3) | |
|
Yes, this is a homework assignment. We never did any vectors in class, but thank you, I'll see the page and try to do it. :) | |
|
|
|
| Kart (45) | |||
|
@ Amishuchak, I must admit these two forum members are pros and know more than I do so I suppose their advice is good. However, if your class have not yet reached vectors, not sure if you should jump to use the above model for your solution (in this C++ world, you move from stage 1 to 2)? Have you done arrays? If yes, perhaps you can use arrays instead E.g. with regards to your first set of data (A) Do something along these lines:
Do same for second set of numbers (I will leave you to figure out how to do the Yes/No- I am sure you will know how to use the while loop to do that) Then if you know array calculation, multiply the elements in set a and set b? Just my humble suggestion | |||
|
|
|||