Ticket Office | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Ticket Office

in text office problem my code give the right answer on my compiler and give a wrong answer on sololearn compiler. my code: #include <iostream> using namespace std; int main() { int ages[5]; int nage=ages[5]; float min=nage; for (int i = 0; i < 5; ++i) { cin >> ages[i]; nage = ages[i]; if (nage < min){ min = nage; } } float d=50*(min/100); float total=50-d; cout << total << endl; return 0; }

19th Oct 2022, 4:25 AM
Ali hegazy
Ali hegazy - avatar
1 Answer
+ 1
There is little mistake in your code min value is always giving 0 because you are not storing first value in temp variable min #include <iostream> using namespace std; int main() { int ages[5]; //int nage=ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } float min = ages[0]; for (int i = 0; i < 5; ++i) { int nage = ages[i]; if (nage < min){ min = nage; } } //cout << min; //float d = 50 * (min / 100); float total = 50 - 50 * min / 100; cout << total << endl; return 0; }
19th Oct 2022, 4:36 AM
A͢J
A͢J - avatar