Hi,
I'm working on a CS project, and I'm somewhat stuck on my project. I was wondering if somebody could offer some suggestions or hints to get me moving again.
The project description is as follows. I am given a 12 x 12 array that holds the distances between different cities. I will call this my distance array. For instance, the array entry [2][3] may list the distance between Atlanta, GA and Los Angeles, CA. I also have a second array listing all the cities as well. I will call this my cities array.
Now I am supposed to create a program that displays the cities to the user. The user is then supposed to select a city, or the exit (EOF) option, and the program is supposed to calculate the distance between the selected city and the previous city selected. Once that is done, I am supposed to prompt the user for another selection. The user can either select another city or simply exit the program altogether.
I haven't written any code for this since I'm still confused about two details. Before I explain my problems, here is a brief outline of how I think the program should look.
I know this is a very very short outline, but that is the gist of the program should work. Now my two problems are the following:Code:While ( selection != EOF) {
Print all the menu options, ie. my cities array.
Input a menu option from the user.
Calculate distance and display total distance to the user.
}
1 . How am I supposed to take an input from the user? scanf or getchar? The problem I have is that I need the input to tell the program "Go to this array element in the distance array".
2. I am having problems figuring out how to compute the total distance. Now, in the first selection, the total distance must be zero since the user has not traveled anywhere. I will initialize Total Distance to be zero. However, in the second selection the total distance = previous total + distance [ current selection][previous selection]
My real problem is that I cannot figure out a way to tell the program to go to the appropriate array element. I need the array element to be the one selected that holds the distance between the current selection and previous selection. I don't know how to write this out in C. Any thoughts would be appreciated.
BTW, on second thought I think my 1st question is ill-posed. So if people cannot make sense of it, then it's okay to forget about it.