+ 1

Can someone teach me on the project about ticket office

How to get smallest age??

14th Oct 2021, 8:30 PM
Daniel Kagombe
Daniel Kagombe - avatar
6 Réponses
0
This is how you get the smallest age in an array int temp=ages[0]; for(int i=0;i<5;i++) { if(temp>ages[i]) temp=ages[i]; }
14th Oct 2021, 8:49 PM
Mohammad Matin Kateb
Mohammad Matin Kateb - avatar
0
Explain to me your loop please
14th Oct 2021, 9:12 PM
Daniel Kagombe
Daniel Kagombe - avatar
0
I cannot understand the if statement
14th Oct 2021, 9:13 PM
Daniel Kagombe
Daniel Kagombe - avatar
0
But its working
14th Oct 2021, 9:14 PM
Daniel Kagombe
Daniel Kagombe - avatar
0
First you need a variable (like temp in the example) that starts from the beginning of the array in order to compare all the values in the array inside a loop, then you create a "for" loop that has i as counter and repeats itself as the length of the array, then you define your if statement inside the loop with the condition that if temp(first value of the array) is bigger than the current number in the array change temp's value to the smaller number, this process is repeated until your loop is finished and temp gets smaller as it can and when your loop is finished it reaches the end of your array and the smallest number of all is found which is temp.
14th Oct 2021, 9:21 PM
Mohammad Matin Kateb
Mohammad Matin Kateb - avatar
0
Thanks for the explaination
16th Oct 2021, 5:43 AM
Daniel Kagombe
Daniel Kagombe - avatar