+ 1

Simple Ticket Office issue (help)

i don't understand what i did wrong in solving the Ticket Office problem from Sololearn. here is the problem: Ticket Office You are working on a ticketing system. A ticket costs $10. The office is running a discount campaign: each group of 5 people is getting a discount, which is determined by the age of the youngest person in the group. You need to create a program that takes the ages of all 5 people as input and outputs the total price of the tickets. Sample Input: 55 28 15 38 63 Sample Output: 42.5 The youngest age is 15, so the group gets a 15% discount from the total price, which is $50 - 15% = $42.5 And here it is my code : #include <iostream> using namespace std; int main() { int ages[5],min=1000,total=50; float fin,dis; for (int i = 0; i < 5; i++) { cin >> ages[i]; } for (int i = 0; i < 5; i++) { if(min>ages[i]) min=ages[i]; } dis=(min/100)*total; fin=total-dis; cout<<fin; return 0; } i always get "50" as result. i made the minimum age appear correctly but after trying to calculate the final thing wich is the total minus discount , i get 50 instead of the correct result.

1st Jan 2021, 12:29 AM
Fan Nutsu
Fan Nutsu - avatar
8 Respostas
+ 4
+2 #include <iostream> using namespace std; int main() { int ages[5],min=1000,total=50; float fin,dis; for (int i = 0; i < 5; i++) { cin >> ages[i]; } for (int i = 0; i < 5; i++) { if(min>ages[i]) min=ages[i]; } dis=(min/100.0)*total; fin=total-dis; cout<<fin; return 0; } this is correct
3rd Dec 2021, 10:33 AM
Abdurahimov Hurrambek
+ 1
#include <iostream> using namespace std; int main() { int ages[5],min=1000,total=50; float fin,dis; for (int i = 0; i < 5; i++) { cin >> ages[i]; } for (int i = 0; i < 5; i++) { if(min>ages[i]) min=ages[i]; } dis=(min/100.0)*total; fin=total-dis; cout<<fin; return 0; }
29th Jul 2021, 5:16 AM
Panchasara Jayesh Prakashbhai
Panchasara Jayesh Prakashbhai - avatar
0
Help
28th Apr 2021, 10:08 AM
Queen
Queen - avatar
0
#include <iostream> using namespace std; int main() { int ages[5], total=50; float discount, price; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } float min = ages[0]; for (int i = 0; i < 5; ++i) { if(ages[i] < min) { min = ages[i]; } } discount = (min/100)*total; price = total-discount; cout << price; return 0; }
1st Aug 2021, 12:22 PM
Killua
Killua - avatar
- 1
#include <iostream> using namespace std; int main() { int ages[5],min=1000,total=50; float fin,dis; for (int i = 0; i < 5; i++) { cin >> ages[i]; } for (int i = 0; i < 5; i++) { if(min>ages[i]) min=ages[i]; } dis=(min/100.0)*total; fin=total-dis; cout<<fin; return 0; }
12th Jun 2021, 4:47 PM
Chinmay Anand
Chinmay Anand - avatar
- 2
#include <iostream> using namespace std; int main () { int edades [5], min = 1000, total = 50; float fin, dis; for (int i = 0; i <5; i ++) {cin >> edades [i]; } for (int i = 0; i <5; i ++) { if (min> edades [i]) min = edades [i]; } dis = (min / 100.0) * total; fin = total-dis; cout << fin; return 0; }
14th Oct 2021, 1:27 AM
Nubia Damaris Lopez Castillo
- 3
That or i could define min variable as a float . Thanks that you helped me. Maybe more people will find this usefull somehow so i won't delete it.
1st Jan 2021, 1:00 AM
Fan Nutsu
Fan Nutsu - avatar
- 4
Fan Nutsu, if you change 100, when you calculate "dis" variable to 100.0, everything works.
1st Jan 2021, 12:35 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar