1. (!)Simple array exercise

I'm doing an exercise from a book [First Course in C++].
Write a program which reads 5 numbers into an array and prints out the value of each and every number which has a value less than 10.
This is what I got so far:
Code:
```#include <iostream.h>
#include <conio.h>
int main()
{
int MyArray[5];
int i ;
cout << "Enter 5 numbers"<< endl;

for(i = 0; i<5; i++){
cin >> MyArray[i];
}

int count = MyArray[0] ;
for(i = ; i<5; i++){
if(MyArray[i]< 10)
cout << count ;
getch();
return 0;
}
}```

I feel really bad asking for the solution but I cannot find a way
to print out the darn array elements with a value < 10.
If someone want to put me out my misery, please. Thanks

2. Return is in for loop

your problem is that your return is included in the for loop, also you don't want to output count. Don't you want to output each element in the array that's less than 10? how should you reference each element seperately inside the loop? (Hint: look at the if statement's conditional)
Code:
```int main()
{
...
for(i = ; i<5; i++){
if(MyArray[i]< 10)
cout << count ;
getch();
return 0;
}  <--- move up a couple lines
}```
you should reinitialize i to 0 again as too

3. Code:
```int count = MyArray[0] ;
for(i = ; i<5; i++){    //??? set i = 0.
if(MyArray[i]< 10)
cout << count ;
getch();    //You may want this to be outside the loop.
return 0;  //This definitely should be outside the loop.
}```
You don't really need count, just print out MyArray[i] instead of trying to print count (which as wwfarch said, isn't what you're trying to do).

4. Hi Hunter2,

>> getch(); //You may want this to be outside the loop.
>> return 0; //This definitely should be outside the loop.
Oops! sorry, I overlooked that.

>> You don't really need count, just print out MyArray[i] instead
>> of trying to print count.
Thanks for that. I got a bit confused with the value of the loop and the value of the array I guess

Here it is, simple... but working:
Code:
```#include <iostream.h>
#include <conio.h>
int main()
{
int MyArray[5];
int i ;
cout << "Enter 5 numbers"<< endl;

for(i = 0; i<5; i++){
cin >> MyArray[i];
}

for(i = 0; i<5; i++){
if (MyArray[i] < 10)
cout << "The number with a value < 10 is: "
<< MyArray[i] << endl;
}
getch();
return 0;
}```
This is what you meant, ok?
- fizz

5. Yup, that's what I meant Glad you got it working!

6. Can anyone kindly tell me the function of "getch();" and an example?

7. Originally Posted by choykawairicky
Can anyone kindly tell me the function of "getch();" and an example?
getch is a nonstandard function, so what it does may differ from compiler to compiler if it's supported at all. However, most of the time getch means to read a character from standard input without requiring that the return key be pressed. In the above code, getch is used to keep the window that the program is running in alive until the user has finished reading the output.

8. does getch() have any parameters? so would this work
Code:
```...
char achar;
getch(achar);
cout<<achar;```
or could i go

Code:
```...
switch(getch())
{
case 1:
...
...
}```

9. >does getch() have any parameters?
Not usually. It returns the character read. Your first example would be changed to the following.
Code:
```char achar = getch();
cout<<achar;```