Click here to Skip to main content
15,434,147 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
There's a tunnel with two lanes where in both lanes there is a certain count of cars.

All of the cars in lane 1 have the same distance(in meters) and move with the same speed in meters/sec.

All of the cars in lane 2 have the same distance(in meters) and move with the same speed in meters/sec.

From t1 to t2 time, how many meetings between cars will there be? Keep in mind that the count of cars in both lanes is different everytime and the length of the tunnel(in meters) is also different everytime.

What I have tried:

using System;

namespace TunnelWithCars
    class Program
        static void Main(string[] args)
            int tunnelDistance;
            int cars1Count;
            int cars2Count;
            int cars1Distance;
            int cars2Distance;
            int cars1Speed;
            int cars2Speed;
            int timeInSecondsForCarsToMeet;
            int carMeetingsCount;
Updated 15-Jun-22 9:12am

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Just posting your assignment and trivial code with no sign of an attempt to implement a solution isn't going to get you anywhere.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
Share this answer
How do I solve this problem as a program?

start by solving the problem by hand with sheet of paper and pencil.
your program will follow the same procedure.
Share this answer
PIEBALDconsult 15-Jun-22 15:13pm    
... and toy cars.
Patrice T 15-Jun-22 15:15pm    
Indeed, it can help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900