+ 1

Can anyone provide the code of this simple problem in c++

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

20th Dec 2020, 5:08 PM
591 Ashish Kumar
591 Ashish Kumar - avatar
4 Réponses
+ 3
#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 m,l; l=ages[0]; for( int x=0;x<5;x++){ if(l>ages[x]){ l=ages[x]; } } m=(float)(l*50)/100; cout<<50-m; return 0; }
26th Mar 2021, 3:50 PM
Harshit Agarwal
Harshit Agarwal - avatar
+ 2
#include <iostream> using namespace std; int main() { int l,a[5]; for (int i = 0; i < 5; ++i) { cin >> a[i]; } //your code goes here if(a[0] < a[1] && a[0] < a[2] && a[0] < a[3] && a[0] < a[4]){ l=a[0]; } if(a[1] < a[0] && a[1] < a[2] && a[1] < a[3] && a[1] < a[4]){ l=a[1];} else if(a[2] < a[0] && a[2] < a[1] && a[2] < a[3] && a[2] < a[4]){ l=a[2];} else if(a[3] < a[0] && a[3] < a[2] && a[3] < a[1] && a[3] < a[4]){ l=a[3];} else if(a[4] < a[0] && a[4] < a[1] && a[4] < a[2] && a[4] < a[3]){ l=a[4];} float m=(float)(l*50)/100; float j=50-m; cout<<j; return 0; }
25th Mar 2021, 9:08 PM
Harshit Agarwal
Harshit Agarwal - avatar