+ 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; }
39 Answers
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;
}
+ 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
+ 3
the second cycle is erroneous and redundant, it is completely unnecessary there
+ 3
Congratulation! You real made it by yourself? Find and fixed mistakes?
+ 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;
}
+ 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;
}
+ 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
+ 2
Done 😁 still the same problem
+ 2
Sherlock Holmes, use your deductive method! which one of us is a detective? call me Inspector Lestrade 😆
+ 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.
+ 2
so what's the bottom line? did you find your error in the program code?
+ 2
what worked? show the corrected version
+ 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;
}
+ 2
have you figured out what your mistakes were?
+ 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])
+ 1
To set an initial age to min.
+ 1
Ярослав Вернигора(Yaroslav Vernigora) the problem is that i got the first 3 test cases right but the 4th abd the 5th wrong
+ 1
😁 no, I checked, nothing changes. just assign the amount to 50 and remove this cycle
+ 1
I know what your mistake is, now we will fix it together...
+ 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