- 1

What is wrong here ? only the test case 3 failed and i dont know why ?

#include <iostream> using namespace std; int main() { int s[5]; for (int i = 0; i < 5; ++i) { cin >> s[i]; } int a=s[0]; int b=s[1]; int c=s[2]; int d=s[3]; int e=s[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 ((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; } 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; } return 0; }

25th Nov 2020, 4:32 PM
Koshish Shrestha
Koshish Shrestha - avatar
3 Respuestas
+ 2
Your program will not print anything when ages of all people will be equal, probably you need to find minimum value. Replacing all < by <= may help to find minimum value, if you can provide problem link it will be easy for community to help you. It can simplified, just take w as a large value (greater than constraints on a, b...e) and iterate though all values and do w=min(w, s[i]).
25th Nov 2020, 5:15 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
You need to create a program that takes the ages of all 5 people as input and outputs the total price of the tickets. Sample Input: 55 28 15 38 63 Sample Output: 42.5 The youngest age is 15, so the group gets a 15% discount from the total price, which is $50 - 15% = $42.5 this is qn
25th Nov 2020, 4:35 PM
Koshish Shrestha
Koshish Shrestha - avatar
+ 1
Use if-else instead of only if. Why you are adding redundant code..? You can only find small one in if-else, and after last find y out-of is-else. That removes repeatations.. Simplifies..
25th Nov 2020, 4:44 PM
Jayakrishna 🇮🇳