i really need help here

This is a discussion on i really need help here within the C Programming forums, part of the General Programming Boards category; Sorry, i posted this before, somebody responded but not really with what I needed. I haev not learned arrays so ...

i really need help here

Sorry, i posted this before, somebody responded but not really with what I needed. I haev not learned arrays so im somewhat limited in how i solve this, I really don't know where to begin. I just need an algorithm for it. Thanx..........

Write a program that simulates and stores the qualities of a car. The qualities you should store are the following:

color assignment: Randomly picks one of the five colors and returns the corresponding char to the calling function. This function should be called once at the beginning of the program. The color will not change during the execution of the program.

move car horizontally: This function will need the original X coordinate and the number of spaces you would like to move the car (a negative value will move the car left; positive value will move the car right).
If the car's ignition is not on, this function tells the user that s/he must turn the ignition on first.

If the user tries to move the car beyond the border of the 20 X 20 grid, you should not move the car; instead you should report an error message.

Hints: You may need more parameters than you think.
For either error condition, what value do you think the function should return?

move car vertically: This function will need the original Y coordinate and the number of spaces you would like to move the car (a negative value will move the car up; positive value will move the car down).
If the car's ignition is not on, this function tells the user that s/he must turn the ignition on first.

If the user tries to move the car beyond the border or the 20 X 20 grid, you should not move the car; instead you should report an error message.

Hints: You may need more parameters than you think.
For either error condition, what value do you think the function should return?

turn engine on: This function will turn the car on when it is off. If it is called while the car is on, it should print an error message. In such case, the state of the car should not be changed.

turn engine off: This function will turn the car off when it is on. If it is called while the car is off, it should print an error message. In such case, the state of the car should not be changed.
Hints: What value do you need to give these functions so they can check if the car is on or off?
What is a good value for off and on (like true and false)?

report the state of the car: At any point in the program, the user may want to know the "state" of the car. This function will take all the car's characteristics as parameters and report the status of each (including a copy of the cars position in the grid).
For example:
Car Stats:
Color: Red
Ignition: On
Location: 5,17
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
----R--------------- (the R correspons to the color of the car)
--------------------
--------------------
--------------------

The initial position of the car should be assigned randomly.

After calling the function which assigns a color to the car and assigning the car a position, your program should have an infinite loop. Within the loop, ask the user what s/he would like to do next. For example:

What would you like to do next (1 - turn car on; 2 - turn car off; 3 - change position of car)?

If the user wants to change the car's position, main will prompt the user for a direction (horizontal or vertical) and the distance to move in that direction. Then the appropriate function would be called with suitable arguments.

After the user selects an action, you should call the function which prints the status.

Take away sturct car *nextCar if you don't want to keep track of mulitple cars in a linked list. Now just think of how you can get a value into each one of these data fields by coding your own functions.

I remember you posted this and I'm not sure what everyone else said but I gave you a structure definition and an example on start car and said to show some code of your own before asking. Cant expect people to do your homework but I'm pretty sure everyone is happy to help u.

you were the only person to reply to my other post, and ur post used an array, which I havent learned yet. I really dont know how to start this thing still, becuase each part needs a function and needs to be put together. I dont know how to brgin, and I feel completely overwhlemed. I starts with this

ok well an array is heaps easier than dynamic memory and probly the only way. Now since you basically want a graph of a fixed size then you should use a 2D array which is defined like:

Code:

int color[rows][cols]

where you change the word rows with a number and cols with a number, then any time you need to put a value in you would do:

Code:

color[1][4] = 5;

and that would assign in row 1, col 4 the value 5. Just remember that when accessing a 2D array it starts from 1.
we'll your color function looks fine, just assign the value once you call it to a variable, ie: