#include
using namespace std;
int main() {
int s;
cin>>s;
int t;
cin>>t;
int length=(5/18)st;
cout<<length;
code
return 0;
} The mistake in your code is in the expression (5/18). Since both 5 and 18 are integers, the result of 5/18 is 0 due to integer division (which truncates the decimal part). You need to ensure that the division happens in floating-point to get a correct result.I made a mistake in the coding in tcs exam so no testcases passes but i never thought this would be a problem a i thought cumulatively it will take round of to int . this makes me depressed so much and many others solved the problem but i couldnt what do i lack but other leetcode problems but this kind of basics i didnt know now i placement is in grimsituation what should i focus am i waste in coding how to come out of this depression
Assistant
I'm really sorry you're feeling this way. It's completely understandable to feel upset after facing such a setback, especially when you put in a lot of effort. However, one mistake does not define your entire journey or capabilities. Here's how you can move forward:
Understand the Mistake Thoroughly:
Integer vs. Floating-Point Division: In C++, when you divide two integers like (5/18), the result is also an integer, which truncates the decimal part, leading to 0. To get an accurate result, you should use floating-point numbers:
cpp
double length = (5.0 / 18.0) * s * t;
or
cpp
double length = (5.0 / 18) * s * t;
Type Casting: Alternatively, you can cast one of the integers to a floating-point type to ensure floating-point division:
cpp
double length = ((double)5 / 18) * s * t;
Strengthen Your Fundamentals:
Data Types and Operations: Make sure you're comfortable with different data types (int, float, double) and how operations behave with them.
Operator Precedence and Casting: Understand how expressions are evaluated and how to control them using parentheses and type casting.
Practice Regularly:
LeetCode, HackerRank, Codeforces: These platforms offer a wide range of problems that can help you improve your coding skills and problem-solving abilities.
Mock Exams: Simulate exam conditions to get used to the pressure and improve time management.
Learn from Mistakes:
Review Solutions: After attempting problems, always review the correct solutions and understand where you went wrong.
Iterative Learning: Implement the correct solutions yourself to reinforce the learning.
Seek Support and Feedback:
Join Study Groups: Collaborating with peers can provide new perspectives and help you stay motivated.
Mentorship: Find a mentor who can guide you through your preparation and provide valuable insights.
Maintain a Positive Mindset:
Self-Compassion: Be kind to yourself. Everyone makes mistakes, and what's important is how you respond to them.
Set Realistic Goals: Break down your preparation into manageable tasks and celebrate small victories along the way.
Manage Stress and Well-being:
Healthy Routine: Ensure you're getting enough rest, nutrition, and exercise.
Mindfulness Practices: Techniques like meditation or deep-breathing can help manage anxiety and improve focus.
Remember Your Progress:
Reflect on how far you've come and the skills you've already acquired. This can boost your confidence and motivation.
Prepare Strategically for Placements:
Understand the Format: Familiarize yourself with the types of questions and formats used in placement exams.
Time Management: Practice solving problems within a set timeframe to enhance speed and efficiency.
Stay Persistent:
Resilience: Remember that setbacks are temporary. With continued effort and the right strategies, you can overcome challenges and achieve your goals.
Lastly, you're not alone in this journey. Many have faced similar struggles and gone on to succeed. Use this experience as a stepping stone to improve and showcase your resilience. If feelings of depression persist, consider reaching out to a mental health professional or someone you trust for support.
You're capable of great things—keep pushing forward!