+ 1

When I run my code in a code project I get this as an output " timeout: the monitored command dumped core". What should I do?

#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 i; int min=ages[i]; for (int i =0; i<5; ++i){ if ( ages[i] >min){ min = ages [i]; } } int price; price = 50 * min / 100; cout << price << endl; return 0; }

13th Feb 2022, 7:42 PM
Basma M
3 Antworten
+ 2
Most likely you have been fiddling with pointers and messed something up. Without code nothing more I can say.
13th Feb 2022, 7:46 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 2
** Notify after any edit or updation. In statement : int min=ages[i] ; will cause that error, because I=5 there and it's index out of bounds. You should use int min=ages[ 0 ] ; And according to your logic , if ( ages[I]>min) min=ages[I]; will find maximum value. You should use if ( ages[I] < min) min = ages[I] ; remove int i; u never used it. Hope it helps...
13th Feb 2022, 8:29 PM
Jayakrishna 🇮🇳
+ 1
Thank you so much
14th Feb 2022, 12:38 PM
Basma M