Like Tree1Likes
  • 1 Post By CommonTater

parking lot game

This is a discussion on parking lot game within the C Programming forums, part of the General Programming Boards category; The sign on the attendant’s booth at the XYZ parking lot is XYZ VISITOR PARKING Cars: First 2 hours Free ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    1

    parking lot game

    The sign on the attendant’s booth at the XYZ parking lot is


    XYZ VISITOR PARKING


    Cars:
    First 2 hours Free
    Next 3 hours 0.50/hour
    Next 10 hours .25/hour
    Trucks:
    First 1 hour Free
    Next 2 hours 1.00/hours
    Next 12 hours 0.75/hour
    Senior Citizens: Free of charge

    Write a program that will accept as input a one-character designator (C, T or S)
    Followed by two military numbers in range of 0600-2200 (6:00 A.M to 10:00 P.M). The program should
    Then compute the appropriate charge and the round up time that car was parked.
    The output should be printed for each vehicle , arrival time, departure time and cost. Your program should also provide a summer at the end of each day indicating total cars, trucks, and senior , time and fees. Your program should have loop which ends with ^Z.


    this is the question. im new to C so i didnt use case and breaks.. but i used if and else. my qustion in when i compile it deos not show anything!! why is that??


    Code:
    #include <stdio.h>
     
    int main(void)
    {
      char type;
      int t, in, out;
      int total,truck=0,senior=0,cars=0;
      
       
     do
     {
         while(("%c %d %d", &type, &in, &out)!=EOF)
           {
         printf("car type:\n\n");
         scanf("%c", &type);
         printf("in time:\n\n");
         scanf("%lf", &in);
         printf("out time:\n\n");
         scanf("%lf", &out);
      
      
     t=((in-out)/100);
     
     if (type=='C')
     {
       cars++;
       if (t<=2)
        total= 0;
       else if (t<=5)
       total=(t-2)*0.5;
       else
       total =((t-5)*0.25);
     }
     
     else if (type=='T')
     {
        truck++;
        if (t<=1)
         total=0;
        else if (t<=3)
        total= ((t-1)*1);
        else
        total= ((t-1)*0.75);
      }
      else if (type=='S')
      {
        senior++;
        total=0;
         }
       
      printf("youcame in @:%d", in);
      printf("you left @: %d", out);
      printf("your cost is: %lf", total);
      
       }
       
          
         
       return 0;
     }
    ps im suppose to ask "if you want to conitue". if anybody could help me with that that would be awsome!!!
    thanks
    Last edited by Salem; 10-07-2011 at 11:36 PM. Reason: remove stupid font

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
         while(("%c %d %d", &type, &in, &out)!=EOF)
    What is that supposed to be? (scanf probably)How about instead you do something like:
    Code:
    do
    {
        prompt for input
        get input
        if input is valid
            process input
        if input means to quit
            set quit to true
    while quit is not true

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by hahahaha View Post

    The sign
    I'm going to assume you are visually impaired... because only a blind person needs such a big ugly font.

    What do in time and out time represent? minutes? Hours?
    What if someone checks in at 23:00 and checks out at 02:00 the next day?

    You have an unterminated do loop in there... Your while loop doesn't make a lot of sense. I'd be amazed if your code even compilers. You need to read up on loops in your textbooks or through a good online tutorial (Google is your friend).

    This is a very simple exercise, I can do it in just under 50 lines...
    Last edited by CommonTater; 10-07-2011 at 09:12 PM.
    Salem likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. parking garage program please help anyone please
    By MIKANSI MIEHLEK in forum C++ Programming
    Replies: 2
    Last Post: 08-22-2011, 10:39 AM
  2. Parking Charges Problem
    By kacebug in forum C Programming
    Replies: 8
    Last Post: 06-07-2010, 06:09 PM
  3. parking garage calculator help
    By vgame64 in forum C++ Programming
    Replies: 4
    Last Post: 02-15-2006, 04:54 PM
  4. hosting vs parking?
    By afreedboy in forum Tech Board
    Replies: 5
    Last Post: 09-28-2004, 07:17 AM
  5. Newbie Parking
    By Gamemonkey in forum Linux Programming
    Replies: 4
    Last Post: 12-29-2003, 05:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21