C++ in the exercise ticket office | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++ in the exercise ticket office

I am doing the exercise ticket office and I am wondering if there is an official solution because I think that pointers can play a part in this exercise but my solution includes only if statements(the most) Edit Here is my attempt: #include <iostream> using namespace std; int main() { int ages[5] = { 100,100,100,100,100 }; int ticket = 10; int tempAge = 0; double minAge = 100; double finalPrice = NULL; for (int i = 0; i < 5; ++i) { cin >> ages[i]; tempAge = ages[i]; finalPrice = finalPrice + ticket; for (int x = 0; x < 5; ++x) { if(tempAge < ages[x] && tempAge < minAge){ minAge = tempAge; } } } cout << finalPrice - (finalPrice * (minAge / 100)); //your code goes here return 0; } *I thought pointers would be in need but I didn't need them and don't quite understand their use (except for freeing ram after the purpose of a variable is completed)

6th Jan 2021, 3:32 PM
Akis Kountardas
Akis Kountardas - avatar
2 Answers
0
Pointers are not needed in this exercise. It is more about data types, loops, arrays, and calculations - everything up until the pointers lessons.
8th Jan 2021, 10:21 PM
Brian
Brian - avatar
+ 1
use this i guarantee it will work please upvote me #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here int n = sizeof(ages)/sizeof(ages[0]); int minimum = ages[0]; for(int i=0; i<n;i++) { minimum = min(minimum, ages[i]); } double d = 50*(minimum/100.00); double total = 50 - d; cout<<total; return 0; }
22nd Apr 2021, 9:03 AM
SHREYAS JHA
SHREYAS JHA - avatar