0

Why does not it work?

#include <iostream> #include <math.h> using namespace std; int main() { float a[5]; float w=0; for (int i = 0; i < 5; ++i) { cin >> a[i]; } //your code goes here if (a[0] < a[1] && a[ 2] && a[ 3] && a[ 4] ){ w=50-(50*a[0]/100); cout <<w; } if (a[ 1] < a[0 ] && a[2 ] && a[3 ] && a[4 ] ){ w=50-(50*a[1]/100); cout <<w; } if (a[2 ] < a[0 ] && a[1 ] && a[3 ] && a[4 ] ){ w=50-(50*a[2]/100); cout <<w; } if (a[3 ] < a[ 0] && a[1 ] && a[ 2] && a[4 ] ){ w=50-(50*a[3]/100); cout <<w; } if(a[4 ] < a[ 0] && a[ 1] && a[ 2] && a[ 3] ){ w=50-(50*a[4]/100); cout <<w; } return 0; }

14th Jan 2021, 3:30 PM
pouya trailer
pouya trailer - avatar
5 Réponses
0
pouya trailer Because you have written Hard Code logic.
14th Jan 2021, 4:04 PM
A͢J
A͢J - avatar
+ 2
pouya trailer Yes code should be simple and also if we provide any input output should come. According to your code you have written a[4] a[3] but suppose if there is only 3 value in an array then a[4] will exist? If there is more than 5 values in array then ?
14th Jan 2021, 5:06 PM
A͢J
A͢J - avatar
0
What do you mean?
14th Jan 2021, 4:45 PM
pouya trailer
pouya trailer - avatar
0
That means the code should be simple?
14th Jan 2021, 4:47 PM
pouya trailer
pouya trailer - avatar
0
One question When I enter 34 23 54 12 36 Out put is 38.544 it is wrong the correct answer is 44
14th Jan 2021, 6:03 PM
pouya trailer
pouya trailer - avatar