Click here to Skip to main content
15,918,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this VB project to do in my first year at college,with everything else i can't seem to figure out this bit of code.. Here's some information about it.

Its based on a fictional car hire firm where i have to design a car rental form that an operator fills out while talking to the client on the phone.

There are a number of vehicles involved,but i will use one as an example here.

VW Polo- Daily rate... 37.50 weekly rate... 236.25...Fortnightly Rate... 448.90

Extras.. Child Seat... 22.00 Sat-Nav... 5.00 Roof Rack... 45.00.(client has a choice of one or all)


If the customer requires the car for 16 days(this number is just an example,it could be any number of days depending on the overall rental period) the cost is calculated by applying the fortnightly rate and adding two extra days at the daily rate.The prices are quoted excluding VAT(20%).

I have figured out the code that calculates the total number of rental days using the datetimepicker in Visual basic express.

I have declared the rental rates and cost of extras as constants in the public class
and vehicle choices are made by clicking on a radiobutton allocated for each vehicle,checkboxes for extras.

With this information i need to calculate the TOTAL COST of the rental using the MOD operator.
Posted
Updated 23-Nov-12 14:37pm
v2

1 solution

The mod operator is effectively part of the division operator: divide gives you the quotient, mod gives you the remainder.
In the example you give, 16 days at the fortnightly rate:
16 / 14 = 1  (since there are 14 days is a fortnight)
16 Mod 14 = 2 (since there is a remainder of 2)
So all you need to say is:
VB
Dim daysAtFortnightRate = daysRented / 14
Dim daysAtDailyRate = daysRented Mod 14
Then all you have to do to work out the cost, is multiply each by the relevant rate and add then two values together.
 
Share this answer
 
Comments
Crispanvarro 23-Nov-12 20:58pm    
Thanks for that,i was wondering if you could possibly clarify it a bit more(i'm a complete novice,but learning :)
I was thinking yes i would declare the relative variables i.e Totalrental days,weeklyrate,fortnightly rate and then use the IF function to calculate the over all total.You obviously would know better,my backs against the wall here,i hope you get back to me.
OriginalGriff 24-Nov-12 2:41am    
If you use division and Mod you don't need the IF - the remainder from fortnightly is 0 to 13, so you feed that into weekly.
The remainder from weekly is 0 to 6, so you feed that into daily. All you need to do is multiply the quotient by teh appropraiet rate, and use the remainder for the next one.
I can't give you code, without doing all the work for you! It really is that simple! :laugh:
Crispanvarro 25-Nov-12 20:06pm    
Thanks Griff remember i'm a complete novice when it comes to VB so your replies may seem simple to you but to me.. well,not so much.Looks like i'll have to settle for a fail on this one and concentrate on the othe modules(SQL,HTML,CSS these i can get my head around)but if you do deside to do a complete stranger a solid,it would be a mature students early xmas prezzy.. ALL the best dude
OriginalGriff 26-Nov-12 2:49am    
I'm not doing your whole homework for you! :laugh: I don't get the credit for it... :)
If you "settle for a fail on this one" then you will fail big time when it comes to SQL. This is a simple exercise, intended to get you thinking about how to do things. It really is not complicated. Try this: do it on paper with a pencil. You will see what is involved pretty quickly: what inputs you have, what output you want, and the processes to get from one to the other.
If you make a note of those processes, (i.e. the actions you take as a person to get from the inputs to the outputs) it should be pretty clear what you need to do in code. Writing the code is the easy bit! :laugh:

Don't give up this early. If you do, then it's hard to get back from there, because the next exercise will assume that you understand this one...
Crispanvarro 26-Nov-12 17:44pm    
Thanks for the great advice griff,your right and you know it :)I will stick with it and i'll get there in the end,everybody was a novice at some stage i suppose.Tanx again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900