# Simple program with my little initiative (code+explanation required)

• 04-25-2012
jensonbutton
Simple program with my little initiative (code+explanation required)
Hi!

I'm looking for someone who woudl be keen to guide me and explain to me how to write this program in ANSI C.
I'm not looking for some crib, mainly I would like to understand the code. So maybe some code with additional comments ?

In order not to look like look like a shirker, I'm keen to give you some personal suggestion about algorhytm.
Unfortunately, currently I'm not capable of spending any money on my personal project, so disinterested people are required.

Workers at the office have to visit their clients constanstly. The office policy is very enviromently friendly,
that is why the use only electric engined cars. Unfortunately cars they're using are not sufficient, nor have long
range without recharging. Additionaly, the office require from it's workers to have obligatory pause at work. Due to
this unique regulations, workers have to stop their cars and lodge in roadside motels EVERY TIME their cars run out of juice.
Write the program, which will help the worker to plan his journey, so that he won't stop at the motels unnecessarily.
Most efficient solutions required (less stops means less motels, ergo less expenses).

Program has to detect situation in which motels are too far away from each other, in which case it should
display some massage, for instance: ERROR !

INPUT

Program will be given certain amount of kilometres to cover (N) on certain route,
range of electric car which could be exploit per ONE DAY (K) and (M) number of motels which are
available on the journey.

We assume that in m- lines there will be given distances between certain motels from the start of the journey.
We assume that distances are represented by integral numbers.

Distances between each motels will be ordered by size (number of kilometres), from the shortest distance to the longest.

1<=n<=1000000
1<=k<=5000
0<=m<=1000000

OUTPUT

Program is meant to display on OUTPUT minimal number of stops, which is needed to cover the distance which is received by program
at the beggining. If journey with specified paramateres will not live up to given requirements, program should display message
for instance WRONG SPECIFICATION !. We assume that at the beggining the batteries in the car are fully charged up !

Example

IN

3000
800
6
100
200
850
1600
2300
2900

OT

4

Here's my IDEA ! ALGORYTHM !

Let's put distances between motels to the array. Then use some if statements to check if there's is enough distance to cover by the vehicle to reach destination of next motel.

I've have some code, but I've only manage to declare variables and did something strange with if().

Could you please, help me out with this ?

I would like to understand the code, so I'm not expecting only pure code without comments.
If you're keen to help me, contact me via e-mail: panzyciaismierci1(at)interia.pl
It's quite important not to publicate any solution in this thread, cause it will simply ruin my anonymous and my academic teacher would persumably kill me ;)
• 04-25-2012
claudiu
Are you trying to implement this for real world use, or are you just messing around trying to get some practice? If you drive as much as I do you should know that the quickest or most economical way between two points is not necessarily the shortest route. If you want to cross central London at rush hour from West to East the shortest route is through the center, however that will require a good three hours of your time. If you use the beltway you might reduce your travel time by up to 50%. Just something to think about.
• 04-25-2012
jensonbutton
Well, if I tried to implement this for real world use, I wouldn't be posting this thread, cause simply, as professional programmer who has been given some task I would know how to write this code. Unfortunately, I'm in a hurry, I'm doing this for my study. I was trying many different ways to even write this code, because I didn't even get to this point when I can compile it ! My teacher is quite badass, and after 2 months of learning ANSI C, he requires to write programs at this level of "difficulty"...
It may sound ridiculous ! But it's true, I'm not writing this just to convince you that I'm not lazy slacker, but to give you an idea that simply I'm not capable of writing this program on my own !

Cheers grosjean

Also I would like to point out, that we're using ONLY ONE WAY. Which means, we're moving only in one direction in straight line, it's like imaging straight line with dots on it (which symbolize clients) !
• 04-25-2012
claudiu
Ok, well unfortunately the way it works here is : no code - no help. I suggest you read the homework policy for the forum.
If however, you are willing to do the work, and post here questions along the way, then that is a completely different story.
• 04-25-2012
jensonbutton
Would it help if I post some basic lines in code, being about less than 10% of total code's lenght. Trust me, I would love to do this HM on my own, unfortunately don't have enough skills and can't mull it over since I'm learning ANSI C for 2 months.
If YES, I will post my "basic" code as soon as possible.
• 04-25-2012
claudiu
People here will not write functionality for you. They will tell you how to approach issues, how to model your data and how to debug your program, but they won't actually do it for you. You have to do the work, because it is your homework and we won't help non-programmers take our jobs.
• 04-25-2012
jensonbutton
Oh... c'mon, do you believe that I will ever be able to threat your job ?

I won't poste 100% of code, cause SIMPLY I'M TO FRESH-FACED to do it, I can show you my initiative by posting something that I'm capable of, which are elementary, basic things, I'm keen to learn something, but don't have enough knowledge to use non-familiar options which probably will solve my problem...

• 04-25-2012
claudiu
If you were not too fresh-faced to take the class, you are not too fresh faced to do the homework.
• 04-25-2012
jensonbutton
Yeah, you're absolutely right. Unfortunatenly, my teacher isn't bright enough and he likes to punish his students. I will post code anyway. Maybe someone will understand me.
• 04-25-2012
jensonbutton
Here's something I've managed to write.

Code:

```#include <stdio.h> int main(){ int N, K, M, i, distance_motel_start=0, tab_of_total_distance[]; printf("Please type, distance (in km) you want to cover on the route\n"); scanf("%d", N); printf("Please type, range (in km) of your car per 1 day\n"); scanf("%d", K); printf("Please type number of motels which are available on the journey\n); scanf("%d", M); int i=1; while (i<M) { ++i; printf("Please type distance between the motel and starting point); scanf("%d", &distance_motel_start); tab_of_total_distance[]++; } if(tab_of_total_distance[]>N){ printf("WRONG SPECIFICATION"); } return 0; }```
I'm wondering if it's any good...
• 04-29-2012
Alan.Brown
Have you tried to compile and run your code. That should be an easy task - even for you.

If you have, post the output here. Maybe it works!! Beginners luck!!