Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 49
  1. #11
    C.I.A.
    Join Date
    Apr 2009
    Gender
    Female
    Posts
    8,813
    Blog Entries
    39

    Default Re: (Help) Parking Lot C Programming.


    dissect your program....
    declaring variables, pede rana:
    int ehour, emin, exhour......etc.;

    Pero wa bitaw ko kibaw nsay sayup ani.
    Di ko kamao aning pointers gud. Hehe.
    kung main program rani, walay functions, basin kamao rako.
    Last edited by kurdapia.nikki; 02-05-2012 at 10:05 PM.

  2. #12

    Default Re: (Help) Parking Lot C Programming.

    sayop imo pointers..mahug na wala cya value man..mata2x ra ni ako kay wa koy vb dri sa laptop

  3. #13

    Default Re: (Help) Parking Lot C Programming.

    I agree with imaceda you should try to code more clean. for example instead of using a switch why not used an if-else instead. Ang problem with switch man gud is dili nimo dali makita ang boundery between sa iyang mga case so mas nindot siya gamiton para sa mga one liner na codes like assignment and etc. sa pointers sad mas ok if you would use '&' instead of '*' in passing reference as a parameter. mas neat siya tan.awon imong codes and dili na nimo needed gamiton ang '*' you only need to use '*' if you need the reference id jud, like in the case sa arrays.

  4. #14

    Default Re: (Help) Parking Lot C Programming.

    Quote Originally Posted by fixyourself View Post
    Code:
    #include<stdio.h>
    int main(void)
    {
      printf("Do your assignments, ayaw epasa sa laing taw..");
      return 1;
    }
    ka harsh pud aning fixyourself oe. hehehe

  5. #15

    Default Re: (Help) Parking Lot C Programming.

    ok ra man mangayo ug tabang bosing...

  6. #16

    Default Re: (Help) Parking Lot C Programming.

    kita ko sa problem bai

    sa imong variables walay mga sud igka pass sa iyang mga function.

    e check lang bai.

  7. #17

    Default Re: (Help) Parking Lot C Programming.

    TS kamao na ka mo gamit pointer? murag sayop na imong pag gamit mga pointer TS.

    maypa gamit ka nalang og Global variables para mas sayon nalang.

  8. #18

    Default Re: (Help) Parking Lot C Programming.

    TS sayop imong mga calculations ra TS


    90 - startime (1 hour and 30 minutes)
    370 - end time 6 and 10 minutes
    end time - startime

    370 - 90
    280 mod 60 = 40 min (total minutes)
    280 / 60 = 4 hours (total hours parked , rid of the decimal)


    so total hours and minutes
    4 hours and 40 minutes

  9. #19

    Default Re: (Help) Parking Lot C Programming.

    Quote Originally Posted by haxors View Post
    Mao ni ang code:

    #include "stdafx.h"
    #include <stdio.h>
    #include <stdlib.h>

    void getData(int* ehour, int* emin, int* exhour, int* exmin);
    void rate(int exhour, int exmin, int ehour, int emin, int* thour, int* tmin, int* round);
    void charge(char* vehic, float* rate1, float* rate2, int ehour);
    void result(int exhour, int exmin, int ehour, int emin, int thour, float rate1, float rate2, int round, float total);

    int main(void)
    {
    char vehic;
    int ehour;
    int emin;
    int exhour;
    int exmin;
    int thour;
    int tmin;
    int round;

    float rate1;
    float rate2;
    float total;

    getData(&ehour, &emin, &exhour, &exmin);
    rate(exhour, exmin, ehour, emin, &thour, &tmin, &round);
    charge(&vehic, &rate1, &rate2, ehour);
    total= rate1 + rate2;
    result( exhour, exmin, ehour, emin, thour, rate1, rate2, round, total);

    getch();
    }

    void getData(int* ehour, int* emin, int* exhour, int* exmin)
    {
    char v;

    printf("Enter C for car, B for bus, T for truck: ");
    scanf("%c", &v);
    printf("\nHour vehicle entered 0-24: ");
    scanf("%d", &ehour);
    printf("\nMinute vehicle entered 0-60: ");
    scanf("%d", &emin);
    printf("\nHour vehicle exited 0-24: ");
    scanf("%d", &exhour);
    printf("\nMinute vehicle exited 0-60: ");
    scanf("%d", &exmin);
    return;
    }
    void rate(int exhour, int exmin, int ehour, int emin, int* thour, int* tmin, int* round)
    {
    if(emin < exmin)
    {
    emin= emin + 60;
    exhour= exhour - 1;
    }
    *thour = ehour - exhour;
    *tmin = emin - exmin;
    if ((*tmin > 0 && *tmin <= 60))
    {
    *thour = *thour + 1;
    *round = *tmin * 0;
    }
    return;
    }
    void charge(char* vehic, float* rate1, float* rate2, int ehour)
    {
    switch (*vehic)
    {
    case 'c': if (ehour <= 3)
    {
    *rate1 = 0.00;
    if (ehour > 3)
    *rate2 = 22.50 * (ehour - 3);
    }
    break;

    case 't': if (ehour <= 2)
    {
    *rate1 = 1.00 * ehour;
    if (ehour > 2)
    *rate2 = 2.30 * (ehour - 2);
    }
    break;
    case 'b': if (ehour <= 1)
    {
    *rate1 = 2.00 * ehour;
    if (ehour > 1)
    *rate2 = 3.70 * (ehour - 1);
    }
    break;
    }
    return;
    }
    void result(int exhour, int exmin, int ehour, int emin, int thour, float rate1, float rate2, int round, float total)
    {
    printf("\n\t\t PARKING LOT CHARGE \t\t\n");
    printf("\nType of vehicle: Car or Bus or Truck");
    printf("\nTIME-IN\t\t %d:%d", ehour, emin);
    printf("\nTIME-OUT\t\t %d:%d", exhour, exmin);
    printf("\n\t\t\t --------");
    printf("\nPARKING TIME\t\t %d:%d", thour, round);
    printf("\n\t\t\t --------");
    total= rate1 + rate2;
    printf("\nTOTAL CHARGE\t\t %4.2f\n\n", total);

    getch();
    }
    TS, kindly check your conditions in this function:
    Code:
    void charge(char* vehic, float* rate1, float* rate2, int ehour)
    {
    	switch (*vehic)
    	{
    		case 'c': 
    		if (ehour <= 3) // this condition have 3 as the maximum acceptable value.
    		{
    			*rate1 = 0.00;
    			if (ehour > 3) // IMO, wala ni chance nga moTrue 
    				*rate2 = 22.50 * (ehour - 3);
    		}
    			break;
    		case 't': 
    		if (ehour <= 2)
    		{
    			*rate1 = 1.00 * ehour;
    			if (ehour > 2)
    				*rate2 = 2.30 * (ehour - 2);
    		}
    			break;
    		case 'b': 
    		if (ehour <= 1)
    		{
    			*rate1 = 2.00 * ehour;
    			if (ehour > 1)
    				*rate2 = 3.70 * (ehour - 1);
    		}	
    			break;
    	}
    	return;
    }
    "if (ehour <= 3)" <-- the maximum value this condition can accept is 3.
    inside this if statement you have "if (ehour > 3)" this expects a value higher than 3. IMO this if statement don't have a chance to pass the condition.

    for char* vehic. You don't have to use pointer for this one. You are treating it as an input instead of an out variable to your function and you are not treating it as an array as well. so IMO char vehic, can suffice.

    For this function I also have a bad feeling.
    Code:
    void getData(int* ehour, int* emin, int* exhour, int* exmin)
    {
    	char v;
    
    	printf("Enter C for car, B for bus, T for truck: ");
    	scanf("%c", &v);
    	printf("\nHour vehicle entered 0-24: ");
    	scanf("%d", &ehour);
    	printf("\nMinute vehicle entered 0-60: ");
    	scanf("%d", &emin);
    	printf("\nHour vehicle exited 0-24: ");
    	scanf("%d", &exhour);
    	printf("\nMinute vehicle exited 0-60: ");
    	scanf("%d", &exmin);
    	return;
    }
    I'm quite concerned about ehour, emin, exhour and exmin variables in scanf. AFAIK, ehour and the rest i mentioned is already an address since it is declared as a pointer, wouldn't it cause an error or a garbage value if you do something like scanf("%d", &ehour);? shouldn't it be like this scanf("%d", ehour); ?

    Kindly check it TS.

    To other posters, if I got something wrong, just correct me.

  10. #20

    Default Re: (Help) Parking Lot C Programming.

    Code:
    //copyright emailroy2002!  FTW!
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <math.h>
    
    char vtype;
    int ehour;
    int emin;
    
    int xhour;
    int xmin;
    
    void getData(void);
    
    int calculate_charges(int eh, int em, int xh, int xm);
    int get_parking_rates(char vtype, double total_hrs, double totalmins);
    
    int main(void){    
        getData();         
        
        calculate_charges(ehour, emin, xhour,xmin);
        getch();
    }
     
    void getData(){
        printf("Enter C for car, B for bus, T for truck: ");
        scanf("%c", &vtype);         
        
        printf("\nHour vehicle entered 0-24: ");
        scanf("%d", &ehour);
        printf("\bMin vehicle entered: ");
        scanf("%d", &emin);         
    
        printf("\nHour vehicle left 0-24: ");
        scanf("%d", &xhour);
        printf("\bMinuite vehicle left: ");
        scanf("%d", &xmin);     
        
    
    }
    
    int calculate_charges(int eh, int em, int xh, int xm) {
        int start, end, totaltime;    
        double totalmins, total_hrs;
    
        start = (eh * 60) + (em);
        end = (xh * 60) + (xm);
    
        totaltime = (end - start);
        
        total_hrs =    (totaltime / 60);
        totalmins = ( totaltime % 60 );
        
        if (eh > 24 || xh > 24) {
               printf ("\nYour Automobile has been towed away!");      
        } else {
            get_parking_rates(vtype, total_hrs, totalmins);
            }
    }
    
    
    int get_parking_rates(char vtype, double total_hrs, double totalmins) {  
    
          double parking_rate, total_parking_fee;   
          
          //self explainatory (add more calculation for parking here
          if (vtype == 'c') {  parking_rate = 10.50; }  else { parking_rate = 25.50; }
                    
          
          printf ("\nAutomobile type %c  Entered At  %d : %d : Exited at %d : %d \n", vtype, ehour, emin, xhour, xmin);                       
          printf("\n\n\bTotal Parking Time : %f  hours and %f minutes " , total_hrs, totalmins  );
          
          total_parking_fee =  total_hrs * parking_rate;
          
          printf("\n\n\bTotal Parking charge %f" ,  total_parking_fee);
    }
    
    
    
    
    //copyright emailroy2002!


    akong gi usab imong code, murag liboga na pointer oi! akong gi simple , tayaon na akong utok..

    sorry! ayaw lang gamita kung di ka nahan TS.

    pero naa nay idea diha.. usba lang nang naay " //self explainatory (add more calculation for parking here" ikaw na ana!

    babush! FTW!
    Last edited by emailroy2002; 02-08-2012 at 01:03 AM.

  11.    Advertisement

Page 2 of 5 FirstFirst 1234 ... LastLast

Similar Threads

 
  1. C/C++ i need help in making a program
    By mE_bytes in forum Programming
    Replies: 54
    Last Post: 07-30-2008, 05:41 PM
  2. Need help in Installing Java programs in my Samsung D880
    By Soj in forum Software & Games (Old)
    Replies: 0
    Last Post: 04-24-2008, 06:34 PM
  3. Replies: 12
    Last Post: 04-17-2008, 04:48 PM
  4. Replies: 10
    Last Post: 03-06-2008, 05:26 AM
  5. NEED HELP ON ACCESS-based programming
    By recanada in forum Programming
    Replies: 1
    Last Post: 04-26-2006, 05:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top