| byronflds (96) | |||
I need help with the loop of my array program. The point of the program is to ask a user for a certain number of integers and then read that number of integers into arrays. the code I have compiles but it just prints out the copyright notice reads the number of integers and then exits.
| |||
|
|
|||
| HellfireXP (71) | |
|
OMG! First of all, PLEASE do not use the lowercase letter "L" as a variable. It looks too much like the number 1 and will confuse other programmers. Second, change your for () statement to: for (k=0; k < l; k++)You also might want to add a prompt message before your cin statement in the for loop. | |
|
Last edited on
|
|
| byronflds (96) | |
|
yeah I was just being lazy on that one. Thanks for the input. IT works now. But what kind of loop would I need to use for the program to print out the elements one after the other after all the integers have been entered. i.e. element 1 is: element 2 is: element 3 is: | |
|
|
|
| Darkmaster (494) | |
|
for, while or do up to you if you know how to use them | |
|
|
|
| byronflds (96) | |
|
yeah I understand and know how to use these loops. I guess the only thing I can't quite figure out right now is how do I code: cout << array[k]; and make sure I get each different value for k. | |
|
|
|
| byronflds (96) | |
| nevermind I had an aha! moment soon as I typed that . | |
|
|
|
| byronflds (96) | |
|
okay last problem. How could I could this program to tell whether or not the integers entered are in ascending or descending order . I tried if(array[k] > array[k++]) { cout << "array is in descending order" << endl; } | |
|
|
|
| Darkmaster (494) | |
|
you only check 2 elements there, not the whole array also you dont check for k < k+1 also change k++ to k+1. it doesnt work as index | |
|
Last edited on
|
|