Can someone come up with a simple code that will add one everytime I press "press any key to continue"?
I have made an array that will spit out a list of numbers but I am trying to make it just output a number each time to my array. Here is my code for an array btw:
pressing a key and entering a key is different. If you want when they actually press you are going to have to use a non-standard method. As far as the counter that is pretty straight forward something like:
I'm not sure what your trying to do, so I'll just go by what your code is saying.
1.) You are only making two element in it. you've got the right idea for the for loop, but like I said before, there's only 2 elements so writing j < 10 isn't necessary.
2.) The loop goes through because the system pause is outside the loop. If it were to do as you said, it would look something like this:
What I am trying to do is get an array that spans from your desire, for argument sake 10.
Instead of the code giving me 1 2 3 4 5 6 7 8 9 10
I'm trying to make a loop that goes
1
Press any key to continue . . . //press key
2
Press any key to coninue . . .// and so on, up to 10 in my example.
This is not hw hence it is simple code. I am trying to apply it to something a lot more complex. I am a novice.
Little Bobby Tales, there are two elements in an array that is:
int array1[1]
It starts with [0] which is the first element and [1] is the second element.
demondiamond, do you want the array to have no values before the loop of outputting the values is or do you want the values preset before the cout loop activates?
preset and when I int arr[0] it gives me an error saying array must be greater than zero, but that has nothing to do with this or me. Present not like cin >> input; type of thing. Just a loop that outputs an element of the array every time u press enter.
Ok it worked regardless, but I will always add it, because I'd rather be safe than sorry, especially when programs get way more complicated. Here's the end result, but yeah I could put a million if I liked. Thank you jazpen. And when it came down to it, it seemed like a miss place of swirly brackets.
@ldm: is nul a special windows keyword then? regardless you still shouldnt use system pause.
Little Bobby Tales, there are two elements in an array that is:
int array1[1]
It starts with [0] which is the first element and [1] is the second element.
no... thats wrong. that creates an array of one element. if you want an array of two elements, then you can do int array[2] and then access like this: array1[0] /*first element*/; array1[1] /*second element*/
also creating an array of 100 elements isnt good. i would use one of the stl containers