I am stuck on writing the math part. I do not know if I put this asa \"#define\"
ID: 3613422 • Letter: I
Question
I am stuck on writing the math part. I do not know if I put this asa "#define" or what but I have no idea how to write this and waswondering if someone can help me with this. What I have is at thebottom and here is the question:Question:
Prompt the user to enter the following values:
1. Time of Day (hour from 0-23, in military time, let this bet)
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 fordetermining the amount of time you will wait to get a parking spotis:
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 topark.
2. This number of spots available will be a positive integer lessthan 50,000.
3. The number of permits given will be a positive integer less than60,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)
#include <stdio.h>
int main(void)
{
int hour, spots, parking_permits;
float time;
printf ("What hour are you looking for parking? ");
scanf ("%d", &hour);
printf ("How many spots are available thissemester? ");
scanf ("%d", &spots);
printf ("How many parking permits were giventhis semester? ");
scanf ("%d",&parking_permits);
getch ();
return 0;
}
Explanation / Answer
#include <stdio.h>
#include <cmath> // You might have toadd "cmath.h", I'm not sure
#include <iostream> //C++
using namespace std;
intmain(void)
{
int hour, spots, parking_permits;
float time;
printf ("What hour are you looking for parking? ");
scanf ("%d", &hour);
printf ("How many spots are available thissemester? ");
scanf ("%d", &spots);
printf ("How many parking permits were giventhis semester? ");
scanf ("%d",&parking_permits);
time = ( 12 - abs(12 - hour))*(parking_permits/spots);
cout << "You will have to wait " <<time << " minutes to find parking." <<endl; // C++, sorry!
system("pause"); // This is just to pausethe screen. It only works on windows. You can also dogetchar() or something
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.