+ 2

This is the ticket office module question for c++. What is the mistake? I am not understanding this properly. Can someone help?

#include <iostream> using namespace std; int main() { int ages[5]; int a; int b; int x ; float d; float c; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } for (int i = 0; i < 4; i++) { if (x[i] < min) min = x[i]; } cout << min; for (int i = 0; i < 4; i++) { if (x[i] < min) min = x[i]; } cout << min; { a = min ; b = a*50 ; d = b /100 ; c = 50 - d ; cout << c ; } return 0; }

18th Apr 2021, 1:06 PM
Kruti
Kruti - avatar
4 Réponses
+ 2
use this i guarantee it will work please upvote me #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here int n = sizeof(ages)/sizeof(ages[0]); int minimum = ages[0]; for(int i=0; i<n;i++) { minimum = min(minimum, ages[i]); } double d = 50*(minimum/100.00); double total = 50 - d; cout<<total; return 0; }
22nd Apr 2021, 9:05 AM
SHREYAS JHA
SHREYAS JHA - avatar
+ 1
That for loop where you search for min, you should make it i < 5, not 4
18th Apr 2021, 1:39 PM
Michal Doruch
0
How do I find the minimum of the 5 inputs? And how do I use that minimum to calculate price?
18th Apr 2021, 1:07 PM
Kruti
Kruti - avatar