I suggest that you post your current code. Indent it more consistently, please.
I suggest that you post your current code. Indent it more consistently, please.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
here's my current code..
Code:#include<stdio.h> float enter_hours(float w); float calculateCharges(float x,float y); int main () { for (int count=1;count<=3;count++); { float a; float p; float q; printf("Car\tHours\tCharges\n"); printf("%d\t%.1f\t%.2f",count,enter_hours(a),calculateCharges(p,q)); count++; } return (0); } float enter_hours(float w) { scanf("%f",&w); return w; } float calculateCharges(float n,float x) { if (x<=3){ return 2.00; } if (x>3 && x<24){ n=x-3; return 2.00+0.50*n; } if (x==24){ return 10.00; } return x; }
You should use variable names that are more descriptive.
The main problem at this point is that you are reading in the input while calculating and printing the output. You probably should be reading the input into an array, then do the calculation and output using the array.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
but i really don't understand..
the things that you have kindly explained to me seems so hard for me to interpret...
i can hardly understand what you are talking..
i'm so sorry..
could you explain or show me what should i do to undo these warnings...?
"possible use of 'p' before definition in main ()"
thanks..
Why do you pass w as a parameter? Do you use its value? No.Code:float enter_hours(float w) { scanf("%f",&w); return w; }
so it should be like that:
Code:float enter_hours(void) { float w; scanf("%f",&w); return w; }What is n and what is x?Code:float calculateCharges(float n,float x)
Shouldn't be only one input - number of hours spent on the parking?
Where do you initialize this value before calling your function?
What should be the output for 23.5 hours parking?
How do you transfer value returned by enter_hours to the calculateCharges?
Where do you calculate Total?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
yes.. i did use it.. w supposed to be hours input by user..
it is used to calculate the charge..
i posted the question on other thread titled "assistance in function"...What is n and what is x?
please have a look at there and it may kind of explain most of the things you have asked..
there are 3 cars to be included in the systems..Shouldn't be only one input - number of hours spent on the parking?
2.00 + (23.5-3)*0.50=12.25What should be the output for 23.5 hours parking?
i really don't know as i quite new in function..How do you transfer value returned by enter_hours to the calculateCharges?
Where do you calculate Total?
i haven't do the part of total because i already encountered problems without doing the total part...
aren't you going to help me out...???
anyone..
please generously help out as i'm still very weak in c programming...
thanks...
It is inputted INSIDE this function - why do you make it a parameter?yes.. i did use it.. w supposed to be hours input by user..
it is used to calculate the charge..
I do not need your explanation. YOU need this explanation to understand YOUR errorsplease have a look at there and it may kind of explain most of the things you have asked..
So what number of cars is doing in this formula:there are 3 cars to be included in the systems..
Code:2.00+0.50*n;so for 23h 30 min you will charge 12$ 50 cents and for 24h - 10$? Don't you see some contradiction here?2.00 + (23.5-3)*0.50=12.25
In most cases you do something likei really don't know as i quite new in function..
So you firstly initialize a variable - in your case usingCode:float hours = 4.5; float charge = calculate(hours); .... float calculate(float hours_parked) { if(hours_parked <= 3.0f) return 2.0f; if(...) ... return 10.0f; }
hours = get_hours();
call and only then pass it as a parameter to other function
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler