About Loop

Write your question here.

Hi,i have this question : i want the program to tell me the even numbers after i finish entering all the numbers not when im is still writing them but when i get the if (number %2 == 0) outside the loop it only shows one even number. thank you.


[/code]
i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
nt main(){
int max,min,number,sum=0,even,odd;
cin>>max;
cin>>min;
for(i=0;i<=8;i++){
cin>>number;
if(number>max){
max=number;
}
if(number<min){
min=number;
}
sum+=number;
if(number %2 == 0){

cout<<"even number = "<<number;
}
cout<<max<<min<<sum;
return 0;
}


Last edited on
Hi, please use code tags for all of your code - http://www.cplusplus.com/articles/jEywvCM9/

i want the program to tell me the even numbers after i finish entering all the numbers

In that case you're gonna have to save all the numbers, otherwise you would just be overwriting them. You're gonna have to use an array -
http://www.cplusplus.com/doc/tutorial/arrays/
Thank you. We are yet to study arrays but i will have a look at it. it sure looks difficult though!
It's a bit tricky, but use it often enough and you'll get the hang of it =)
Topic archived. No new replies allowed.