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.
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.
sayop imo pointers..mahug na wala cya value man..mata2x ra ni ako kay wa koy vb dri sa laptop
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.
ok ra man mangayo ug tabang bosing...
kita ko sa problem bai
sa imong variables walay mga sud igka pass sa iyang mga function.
e check lang bai.
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.
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
TS, kindly check your conditions in this function:
"if (ehour <= 3)" <-- the maximum value this condition can accept is 3.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; }
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.
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); ?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; }
Kindly check it TS.
To other posters, if I got something wrong, just correct me.
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.
Similar Threads |
|