0

Need assistance with the ticket office Quiz...

Here is My Code it works fine in the PC, I need assistance! #include <iostream> using namespace std; int main(){ int ages[5]; int elementsInArray = sizeof(ages)/sizeof(ages[0]); double totalPercentage = 100.0; double totalCosts = 50; int smallest = ages[0]; for(int i = 0; i < 5; ++i) { cin >> ages[i]; } for(int i = 0; i < elementsInArray; ++i) { if (ages[i] < smallest) { smallest = ages[i]; } } double costsAfterDiscount = totalCosts * ((totalPercentage - smallest)/totalPercentage); cout << smallest << endl; cout << "This is the amount you will have to pay:

quot; << costsAfterDiscount << endl; return 0; }

10th Dec 2020, 4:15 PM
Maleza Israel
Maleza Israel - avatar
6 Réponses
+ 1
Maleza Israel You just need to do double costAfterDiscount = 50.0 - 50.0 * smallest / 100;
10th Dec 2020, 4:42 PM
A͢J
A͢J - avatar
0
Yes, initially I did that but the output in Sololearn App keeps on coming to 49, while trying to debug using the pc the program works well
10th Dec 2020, 4:38 PM
Maleza Israel
Maleza Israel - avatar
0
int smallest = ages[0]; the assignment needs to go after the input loop but before the " find smallest" loop.
10th Dec 2020, 4:50 PM
rodwynnejones
rodwynnejones - avatar
0
Thanks to you all; Pąľľąvī, RodwynneJonnes all of your assistance yielded great fruits, The bug was: I was to place the assignment after the loop!!!, Thanks again. It WORKS!!!
10th Dec 2020, 4:57 PM
Maleza Israel
Maleza Israel - avatar