C/ simple program, big problem (similar to Travelling Salesman Problem)

Discussion in 'C' started by grosjean, Apr 25, 2012.

  1. grosjean

    grosjean New Member

    Apr 25, 2012
    Likes Received:
    Trophy Points:

    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.

    Ok, here's the task.

    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 !


    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.



    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 !






    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 ?

    Also, if you're keen to help me, contact me via e-mail: panzyciaismierci1(at)interia.pl
    Posting answer on forum will destroy my anonimity.

    #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) {
    printf("Please type distance between the motel and starting point);
    scanf("%d", &distance_motel_start);
    return 0;

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice