+ 3

Ticket Office

Why test case 3? I need an answer for this? include <iostream> using namespace std; int main(){ int ages[5]; for (int i + 0; <5; i++){ cin>>ages[i]; } int a= ages[0]; int b= ages[1]; int c= ages[2]; int d= ages[3]; int e= ages[4]; if ((a<b)&&(a<c)&&(a<d)&&(a<e)){ float w=a; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((b<a)&&(b<c)&&(b<d)&&(b<e)){ float w=b; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((c<b)&&(c<a)&&(c<d)&&(c<e)){ float w=c; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((d<b)&&(d<c)&&(d<a)&&(d<e)){ float w=d; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((e<b)&&(e<c)&&(e<d)&&(e<a)){ float w=e; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } return 0; }

10th Dec 2020, 8:29 AM
Lance Darrel Capati
Lance Darrel Capati - avatar
19 ответов
+ 4
include <iostream> using namespace std; int main() { int ages[5]; double out; for (int i = 0; i < 5; ++i) { cin>>ages[i]; } //your code goes here for (int a=1;a<5;++a) { int youngest=ages[0]; if(youngest>ages[a]) { youngest=ages[a]; } double disc; disc = 50.0*youngest/ 100; out= 50-disc; } cout<<out; return 0; } This is the code but it passes only Test 1 ,3 and 5
27th Dec 2020, 11:31 PM
Nathan Aglipay
Nathan Aglipay - avatar
+ 3
#include <iostream> using namespace std; int main() { int ages[5] ; float min = ages[0],p,sum=0; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } for (int i = 0; i < 5; ++i) { if (min > ages[i]) { min = ages[i]; } p = 50*(min/100) ; sum = 50 - p ; } cout << sum ; return 0; }
19th Feb 2021, 1:57 PM
Haidar Ghiath Qanbar
+ 3
you can try mine /*Finding the lowest age as a percent discount*/ #include <iostream> using namespace std; int main() { int ages[5]; // array of 5 empty int for (int i = 0; i < 5; ++i) { cin >> ages[i]; //store while in for loop } int min = ages[0]; // basis of minimum starting from first value for(int i = 0; i < 5; ++i) { if (min > ages[i]) { min = ages[i]; } // replaces the min variable if min is greater than the next value } cout << 50 *(1 - (min * .01)); /* deduct percentage by 1 and multiply by 50 to find the discounted price*/ return 0; }
10th Dec 2021, 11:17 AM
Vinz Ray Pitargue
Vinz Ray Pitargue - avatar
15th Mar 2021, 2:21 PM
Muzaffar Najib
Muzaffar Najib - avatar
+ 2
Visit here for better & easy solution :- https://code.sololearn.com/ca25a21A11a2
31st Jul 2021, 1:04 PM
RAJAT AGRAWAL
RAJAT AGRAWAL - avatar
+ 1
#include <iostream> using namespace std; int main() { int ages[5]; double out; for (int i = 0; i < 5; ++i) { cin>>ages[i]; } //your code goes here for (int a=1;a<5;++a) { int youngest=ages[0]; if(youngest>ages[a]) { youngest=ages[a]; } double disc; disc = 50.0*youngest/ 100; out= 50-disc; } cout<<out; return 0; }
12th Mar 2021, 11:58 AM
Dhaval Kanjariya
Dhaval Kanjariya - avatar
+ 1
Why don't I pass test case 4? #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } if (ages[0] < ages[1,2,3,4] ) { cout << 50 - 50*ages[0]/100.00; } else if (ages[1] < ages[0,2,3,4] ){ cout << 50 - 50*ages[1]/100.00; } else if (ages[2] < ages[0,1,3,4] ){ cout << 50 - 50*ages[2]/100.00; } //your code goes here else if (ages[3] < ages[1,2,0,4] ){ cout << 50 - 50*ages[3]/100.00; } else if (ages[4] < ages[1,2,0,3] ){ cout << 50 - 50*ages[4]/100.00; } else { cout << 50 - 50*ages[0]/100.00; } return 0; }
31st Mar 2021, 5:38 PM
Mario Krcelic
Mario Krcelic - avatar
+ 1
Just add a new if statement with the same code, but for test 3 specifically (all ages are the same). Hence: if ((a == b) && (a == c) && (a == d) && (a == e)){ float w = a; float p = (w / 100) * 50; float y = 50 - p; cout << y << endl; }
3rd Apr 2021, 5:42 PM
SenaL NedNed
SenaL NedNed - avatar
+ 1
✔️✔️✔️✔️✔️All Test cases passed OK #include <iostream> using namespace std; int main() { int ages[5]; int x; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } x = ages[0]; for (int j = 0; j < 5; ++j) { if(ages[j] < x){ x = ages[j]; } } cout << 50-((50.0*x)/100) << endl; return 0; }
24th Mar 2022, 10:11 PM
AYOUB JMOUR
AYOUB JMOUR - avatar
0
all 5 cases are ✔️ #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } int youngest = ages[0]; for (int i = 1; i < 5; i++){ if(youngest > ages[i]){ youngest = ages[i]; } } float discount = 50 * (float)youngest / 100; float price = 50 - discount; cout<< price; return 0; }
28th Jun 2021, 6:28 PM
Gourav Duary
Gourav Duary - avatar
0
#include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here float m; float p; m = ages[0]; for (int x = 1; x < 5; ++x) { if ( m > ages[x]) { m = ages[x]; } } p = 50 - (50*m/100); cout << p << endl; return 0; } it's working
23rd Aug 2021, 10:23 AM
Swadhin Kumar
Swadhin Kumar - avatar
0
You can also try this #include <iostream> using namespace std; int main() { int ages[5]; double finalCost; for (int i = 0; i < 5; i++) { cin >> ages[i]; } //your code goes here double youngest_age; youngest_age = ages[0]; for (int a =0; a < 5; a++){ if (youngest_age > ages[a]){ youngest_age = ages[a]; } } finalCost = 50 - (50 * youngest_age / 100); cout << finalCost << endl; return 0; }
20th Sep 2021, 10:16 PM
Rahinatu Ako Husnah
Rahinatu Ako Husnah  - avatar
0
This was my solution: #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here float min = ages[0]; int arrSize = sizeof(ages)/sizeof(ages[0]); for(int i = 0; i < 5; i++) { if(ages[i] < min) { min = ages[i]; } } float price = (arrSize * 10); float discount = (price/100 * min); float answer = price - discount; cout << answer << endl; return 0; }
12th Apr 2022, 1:28 PM
Steel Morris
0
int main() { int ages[5]; int tsml = ages[0]; for (int i = 0; i < 5; i++) { cin >> ages[i]; } for (int i = 0; i < 5; i++) { if(ages[i]<tsml) {tsml = ages[i];} } cout << 50-((50.0*tsml)/100) << endl; return 0; }
26th Sep 2022, 10:02 AM
Tomek
0
short and good! data = { "100-90": 25, "42-01": 48, "55-09": 12, "128-64": 71, "002-22": 18, "321-54": 19, "097-32": 33, "065-135": 64, "99-043": 80, "111-99": 11, "123-019": 5, "109-890": 72, "132-123": 27, "32-908": 27, "008-09": 25, "055-967": 35, "897-99": 44, "890-98": 56, "344-32": 65, "43-955": 59, "001-233": 9, "089-111": 15, "090-090": 17, "56-777": 23, "44-909": 27, "13-111": 21, "87-432": 15, "87-433": 14, "87-434": 23, "87-435": 11, "87-436": 12, "87-437": 16, "94-121": 15, "94-122": 35, "80-089": 10, "87-456": 8, "87-430": 40 } age = int(input()) ppl_above_18 = 0 ppl_below_18 = 0 ppl_above_age = 0 ppl_below_age = 0 for person_age in data.values(): if person_age < 18: ppl_below_18 += 1 else: ppl_above_18 += 1 if person_age < age: ppl_below_age += 1 else: ppl_above_age += 1 old_amt = ppl_below_18 * 5 + ppl_above_18 * 20 new_amt = ppl_below_age * 5 + ppl_above_age * 20 extra_profit = ((new_amt - old_amt) / old_amt) * 100 print(int(extra_profit))
5th Oct 2022, 3:40 PM
Marcel Krättli
0
short and good! #include <iostream> using namespace std; int main() {int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i];} float m; float p; m = ages[0]; for (int x = 1; x < 5; ++x) {if ( m > ages[x]) {m = ages[x];}} p = 50 - (50*m/100); cout << p << endl; return 0;}
6th Oct 2022, 11:11 AM
Marcel Krättli
- 1
data = { "100-90": 25, "42-01": 48, "55-09": 12, "128-64": 71, "002-22": 18, "321-54": 19, "097-32": 33, "065-135": 64, "99-043": 80, "111-99": 11, "123-019": 5, "109-890": 72, "132-123": 27, "32-908": 27, "008-09": 25, "055-967": 35, "897-99": 44, "890-98": 56, "344-32": 65, "43-955": 59, "001-233": 9, "089-111": 15, "090-090": 17, "56-777": 23, "44-909": 27, "13-111": 21, "87-432": 15, "87-433": 14, "87-434": 23, "87-435": 11, "87-436": 12, "87-437": 16, "94-121": 15, "94-122": 35, "80-089": 10, "87-456": 8, "87-430": 40 } age = int(input()) #your code goes here ppl_above_18 = 0 ppl_below_18 = 0 ppl_above_age = 0 ppl_below_age = 0 for person_age in data.values(): if person_age < 18: ppl_below_18 += 1 else: ppl_above_18 += 1 if person_age < age: ppl_below_age += 1 else: ppl_above_age += 1 old_amt = ppl_below_18 * 5 + ppl_above_18 * 20 new_amt = ppl_below_age * 5 + ppl_above_age * 20 extra_profit = ((new_amt - old_amt) / old_amt) * 100 print(int(extra_profit))
8th May 2021, 4:47 AM
Aman Kaushik
Aman Kaushik - avatar
- 2
Post the challenge description please
10th Dec 2020, 8:39 AM
Benjamin Jürgens
Benjamin Jürgens - avatar