# Thread: C Programming - Having difficulty with this program?

1. ## C Programming - Having difficulty with this program?

As I am writing this code, I have it set up where I can input values, but I am having difficulty with the math part. Do I have to put in "#define" and that formula before the "int main(void)" and insert the equation before the getch()? I know I have to tell the program that a is this, g is that, etc, but that is where I am stuck at. Here is the question and what I have so far is at the bottom:

Question:

Prompt the user to enter the following values:
1. Time of Day (hour from 0-23, in military time, let this be t)
2. Parking Spots Available (for the semester, let this be a)
3. Parking Permits Given (for the semester, let this be g)

After much observation, you have realized that the formula for determining the amount of time you will wait to get a parking spot is:
Time (in minutes) = (12 – | 12 – t |)*g/a

Input Specification
1. The time of day will be a single integer in between 0 and 23, inclusive, representing the hour the user is attempting to park.
2. This number of spots available will be a positive integer less than 50,000.
3. The number of permits given will be a positive integer less than 60,000.

Sample Run
What hour are you looking for parking?
10
How many spots are available this semester?
9000
How many parking permits were given this semester?
45000
You will have to wait 50.00 minutes to find parking.
__________________________________________________ _____________________

(MY WORK SO FAR)

Code:
```#include <stdio.h>

int main(void)
{
int hour, spots, parking_permits;
float time;

printf ("What hour are you looking for parking? \n");
scanf ("%d", &hour);

printf ("How many spots are available this semester? \n");
scanf ("%d", &spots);

printf ("How many parking permits were given this semester? \n");
scanf ("%d", &parking_permits);

getch ();

return 0;
}```

2. You just have to compute your answer, once you have the data. I fail to see why any #define's would be needed at all.

3. Originally Posted by tabstop
You just have to compute your answer, once you have the data. I fail to see why any #define's would be needed at all.
so all I have to do is put in that formula and that's it?
Do I have to specify a, g, and t?

4. Don't use a macro (eg: define) - *always* use functions (execpt in very special circumstances). You must declare the function before main, but you can define it (the actual body of code) anywhere (outside of a function, of course). After you have gathered your input, invoke the function to calculate the formula. The function might look something like:

Code:
```
int expected_wait(int time, int spots_available, int permits_issued)
{
int result = 0;
/*
Formula goes here, assign to 'result'
*/
return result;
}```
And invoking it like so:

Code:
```
int expected_wait_time = expected_wait(hour, spots, parking_permits);```

5. thank you. You guys are helpful.