+ 1
Need some help please
How can i get the youngest age ? 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
7 Antworten
+ 2
Yes but you need to show your some efforts.
+ 2
Cojo Alex
You are just taking inputs but not getting minimum age.
You have to use another loop and store first value in a temporary variable
Now compare temp. variable (minn) with next value of the array..if temp is greater than next value then store next value in temp.
Now you have to get discounted amount so
cout << 50.0 - 50.0 * temp / 100;
+ 2
Cojo Alex
I said store first value in a variable and compare with next value inside second loop.
minn = ages[0];
Check this inside loop:
if (minn < ages[i]) {
minn = ages[i];
}
+ 1
#include <iostream>
using namespace std;
int main() {
int ages[5];
int minn;
for (int i = 0; i < 5; ++i) {
minn = ages[0];
cin >> ages[i];
if (minn < ages[i]) {
minn = ages[i];
}
}
cout << (50.0 - 50.0*minn/100);
return 0;
}
It works now, I have no errors but passes only 1 from 5 tests….
0
I tried a lot. :) I am interested only in that line of code, to get the minimum from the inputs
#include <iostream>
using namespace std;
int main() {
int ages[5];
int minn;
for (int i = 0; i < 5; ++i) {
cin >> ages[i];
}
cout << (50 - minn/100);
return 0;
}
0
Can you explain me what was wrong please?
- 1
I tried something, but still wrong 😬
#include <iostream>
using namespace std;
int main() {
int ages[5];
int minn;
for (int i = 0; i < 5; ++i) {
cin >> ages[i];
}
if (minn = ages[0]) {
} else if (minn > ages++) {
ages = minn;
}
cout << 50.0 - 50.0*minn/100;
return 0;
}