+ 2

My ticket Office tests case4 & 5 are wrong, why?

#include <iostream> using namespace std; int main() { int ages[5]; float min; float sum; float ans; float pay; for (int i = 0; i < 5; i++) { cin >> ages[i]; } for (int i = 0; i < 5; i++) { sum+=10; min=ages[0]; } for (int k = 0; k < 4; k++) { if(min > ages[k++]){ min = ages[k++]; } } pay = (100-min)/100; ans = sum * pay ; cout << ans << endl; return 0; }

27th Apr 2021, 12:26 AM
Hodeni
39 odpowiedzi
0
My variant is: #include <iostream> using namespace std; int main() { int ages[5]; float min; float sum=50; float ans; float pay; for (int i = 0; i < 5; i++) { cin >> ages[i]; } min=ages[0]; for (int k = 0; k < 5; k++) { //min=ages[0]; if(min > ages[k]){ min = ages[k]; } } pay = (100-min)/100; ans = sum * pay ; cout << ans << endl; return 0; }
27th Apr 2021, 10:23 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 4
It doesn’t differ, I just wrote it this way thinking that maybe the 4th and 5th test is checking what if someone entered less than 5 passengers 😅 but I don’t have a proper reason
27th Apr 2021, 12:46 AM
Hodeni
+ 3
the second cycle is erroneous and redundant, it is completely unnecessary there
27th Apr 2021, 8:43 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 3
Congratulation! You real made it by yourself? Find and fixed mistakes?
27th Apr 2021, 10:11 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 3
Sherlock Holmes Try this one: #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } double youngest = ages[0]; for (int a = 0; a <5; ++a) { if(youngest>ages[a]) { youngest = ages[a]; } } double prezzo = 50 - (50*youngest/100); cout << prezzo; return 0; }
27th Apr 2021, 9:25 PM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
+ 3
Use my code its too easy Upvote me if it's helpful #include <iostream> using namespace std; int main() { int a[5]; for (int i = 0; i < 5; ++i) { cin >> a[i]; } float loww; float dc; loww = a[0]; for(int i = 0; i < 5; ++i) { if(loww>a[i]) { loww = a[i]; } } dc = 50 - loww/2; cout<<dc; return 0; }
28th Apr 2021, 7:18 PM
Koushal Sharma
Koushal Sharma - avatar
+ 2
Hi! can I ask you why you are collecting the total cost of tickets in the cycle? it will always be 50, because the ticket costs 10 and the number of passengers is always 5
27th Apr 2021, 12:44 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
Done 😁 still the same problem
27th Apr 2021, 12:49 AM
Hodeni
+ 2
Sherlock Holmes, use your deductive method! which one of us is a detective? call me Inspector Lestrade 😆
27th Apr 2021, 1:49 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
Hahahahaha Ok Mr. Lestrade 😁 I wrote it 4 because I have k++ and in the last iteration k++ will be the last value in the array.
27th Apr 2021, 2:19 AM
Hodeni
+ 2
so what's the bottom line? did you find your error in the program code?
27th Apr 2021, 10:02 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
what worked? show the corrected version
27th Apr 2021, 10:03 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
#include <iostream> using namespace std; int main() { int ages[5]; float min; float sum=50; float ans; float pay; for (int i = 0; i < 5; i++) { cin >> ages[i]; } for (int k = 0; k < 5; k++) { min=ages[0]; if(min > ages[k]){ min = ages[k++]; } } pay = (100-min)/100; ans = sum * pay ; cout << ans << endl; return 0; }
27th Apr 2021, 10:04 AM
Hodeni
+ 2
have you figured out what your mistakes were?
27th Apr 2021, 10:24 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
and why else did we put the value 0 of the position of the minimum age in the array in this loop (min = ages[0])
27th Apr 2021, 12:45 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
To set an initial age to min.
27th Apr 2021, 12:47 AM
Hodeni
+ 1
Ярослав Вернигора(Yaroslav Vernigora) the problem is that i got the first 3 test cases right but the 4th abd the 5th wrong
27th Apr 2021, 12:48 AM
Hodeni
+ 1
😁 no, I checked, nothing changes. just assign the amount to 50 and remove this cycle
27th Apr 2021, 12:48 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
I know what your mistake is, now we will fix it together...
27th Apr 2021, 12:49 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
and now... pay attention to how you reassign the minimum age and compare this with how the ready-made code at the top of the array enters the values of the age of passengers... compare your code and the one
27th Apr 2021, 12:52 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar