0

Help me again please

OK I am making the ticket office code. It takes an array of 5 ages, and my code figures out the lowest age(for example, 11), and then takes that number and makes it a percent, then that percent of 50(11% of 50). I don't understand what my code is doing wrong. #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } int r=ages[0]; if (ages[1]<r) { r=ages[1]; } if (ages[2]<r) { r=ages[2]; } if (ages[3]<r) { r=ages[3]; } if (ages[4]<r) { r=ages[4]; } int e=r/100; int y=50; int h=y*e; int p=50-h; cout << p << endl; return 0; }

3rd Dec 2020, 6:16 PM
Taco Tube
Taco Tube - avatar
9 Answers
0
cout<<float(50-0.5*r);
3rd Dec 2020, 6:31 PM
Hard Maker
Hard Maker - avatar
+ 1
You use 'int', use float in y
3rd Dec 2020, 6:18 PM
Hard Maker
Hard Maker - avatar
+ 1
in my code: cout<<float(50-0.5*min);
3rd Dec 2020, 6:28 PM
Hard Maker
Hard Maker - avatar
+ 1
In your code min is 'r'
3rd Dec 2020, 6:30 PM
Hard Maker
Hard Maker - avatar
+ 1
You are welcome
3rd Dec 2020, 6:35 PM
Hard Maker
Hard Maker - avatar
+ 1
Enjoy ! #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 ma=ages[0]; for(int i=1;i<5;i++){ if (ages[i] < ma){ ma=ages[i]; } } cout << 50 - 50*ma/100; return 0; }
7th Jan 2021, 3:39 PM
דוד אסולין
דוד אסולין - avatar
0
That did not work
3rd Dec 2020, 6:25 PM
Taco Tube
Taco Tube - avatar
0
would min be the percentage(in my code, e)?
3rd Dec 2020, 6:29 PM
Taco Tube
Taco Tube - avatar
0
Thank you!
3rd Dec 2020, 6:34 PM
Taco Tube
Taco Tube - avatar