Problem in C++ task | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Problem in C++ task

#include <iostream> using namespace std; int main() { int ages[5]; int min = ages[0]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } if(sizeof(ages)==20){ for(int i=0; i<5; ++i){ if(ages[i]<min) min = ages[i]; int discout = min/100 * 50; cout<<50-discout; } } else cout<<sizeof(ages)/4*10; return 0; } Not found my problem °-° Solo Learn task - Ticket office in core c++ https://code.sololearn.com/cyoXhsF7WOkC/?ref=app

23rd Nov 2021, 12:57 AM
ᙢᖇ.ᚪ ᚱ ع ℰ 爪 Ꭿ ກ
ᙢᖇ.ᚪ ᚱ ع ℰ 爪 Ꭿ ກ - avatar
2 Answers
+ 1
Don't need to take min variable & don't need to compare the size of the array just sort the array with this. for(int i = 0; I < 4; i++) { for(int j = 0; j < 4; j++) { if (ages[j] > ages[j+1]) ages[j] = ages[j+1]; } } ages[0] will be the smallest age.
23rd Nov 2021, 2:19 AM
zexu knub
zexu knub - avatar
+ 2
1) What are you trying to do when comparing sizeof (ages) with 20 ? ( It will always be true in your case ) 2) why is the calculation of the discount in integers ? 3) why are you printing the output on every iteration of the loop ?
23rd Nov 2021, 1:05 AM
Arsenic
Arsenic - avatar