Why the code prints 50 all the time? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Why the code prints 50 all the time?

I wrote the code and it prints 50 all time. This is my code: #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here int min = ages[0]; for(int g=0; g < min; g++) { if(ages [g] < min ) min = ages [g]; } double result = 50 - (50 / 100 * min); cout << result ; return 0; }

2nd Dec 2021, 4:31 PM
yoel
3 Respuestas
+ 5
I noticed that the maximmum loop is supposed to be 5 you put "min". for(int g=0; g < 5; g++) {
2nd Dec 2021, 4:46 PM
SoloProg
SoloProg - avatar
+ 5
Because the compiler sees an expression with only integers and outputs an integer ☺️: 50/100 = 0.5 => 0 * min = 0
2nd Dec 2021, 4:55 PM
Solo
Solo - avatar
+ 1
Thenk you
2nd Dec 2021, 4:56 PM
yoel