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

C++ project in progress

Not really a question, just sharing my thought process on solving a problem. I'm trying to finish the end-of-Module project for the "Data Types, Arrays, and Pointers" module of the C++ course. Problem can be found at: https://www.sololearn.com/learning/eom-project/1051/904 My solution in Python: https://code.sololearn.com/cJuCR3qjY5qo My solution in C++ (in progress): https://code.sololearn.com/crl12QTk2Ocu // 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. I worked out the solution in Python, just to make sure I knew what I was trying to solve, and to get an idea of how to approach it in C++. Python solution in four lines: Ages = list(map(int, input().split())) Discount = min(Ages) / 100 Total = 50 - (50 * Discount) print(Total) In one line: print(50 - (50 * (min(list(map(int,input().split())))/100))) So, to do this in C++, at least for this project, I have to assume there is no min() function, which means I'll have to use a for loop to do the job. Also, no map() function. Converting the values from string to int will have to be done with a for loop also. This is my C++ solution, or at least the commentary: #include <iostream> using namespace std; int main() { // convert the string input into a list // convert the string objects into int objects // isolate the min int object // do the math: 50 - (50 * (min / 100)) return 0; } I know this should be a simple job, but even looking at the C's these days gives me a bit of a headache.

20th Jul 2022, 4:20 PM
Jimmy Tyrrell
Jimmy Tyrrell - avatar
3 Answers
+ 1
Nice you shared it. But as per guidelines, pls use feedpost for sharing your knowledge and information. This section is only for question and answers. Also sharing code coach solutions are spoiler alert.. And i think, task give you 5 inputs in separate lines.. In c++, you can directly accept input as integer.. Thanks for your understandings..
20th Jul 2022, 4:34 PM
Jayakrishna 🇮🇳
+ 1
@ Jayakrishna🇮🇳: The reason I posted this in the question section, is because there are many details I don't know the answers to. For instance, I didn't know that in C++, a program can accept input as an integer without needing to be converted. Thanks for that information :) The only functioning code in this post is in Python, and this is a C++ problem, so no answers are being given away.
20th Jul 2022, 4:40 PM
Jimmy Tyrrell
Jimmy Tyrrell - avatar
+ 1
What I mean is you have no question. You can ask questions here. If you want share information or knowledge, use feed post. You can help others in a way you added in c++ code.. Or through answering others questions or posting it feed post section.. But not code solution as py code. That the only information I passing, Thanks for understanding..
21st Jul 2022, 12:11 PM
Jayakrishna 🇮🇳