To add to what
steveb
has said, you can think of a function as "teaching the computer to do something" and the parameters as the "bits it needs to do it to".
If you think about a cooking recipe it has two parts: teh ingredients and the method.
The ingredients tells you how much ot each item to use, the method tells you what to do with it.
So if I create a recipe for a Gin and Tonic:
Ingredients:
50ml Gin
200ml Tonic water
2 cubes Ice
1 slice Lemon
Method:
Put the Gin in the glass.
Add the ice cubes.
Add the Tonic water.
Add the lemon.
You can vary that by making enough for two:
Ingredients:
100ml Gin
400ml Tonic water
4 cubes Ice
2 slices Lemon
Method:
Put the Gin in the glass.
Add the ice cubes.
Add the Tonic water.
Add the lemon.
Or "weaken it":
Ingredients:
25ml Gin
200ml Tonic water
2 cubes Ice
1 slice Lemon
Method:
Put the Gin in the glass.
Add the ice cubes.
Add the Tonic water.
Add the lemon.
Or make a "VirGin & Tonic":
Ingredients:
0ml Gin
200ml Tonic water
2 cubes Ice
1 slice Lemon
Method:
Put the Gin in the glass.
Add the ice cubes.
Add the Tonic water.
Add the lemon.
The method doesn't change at all, just the ingredients.
In computing, the "Method" part of the recipe is the function, the Ingredients part is the function parameters:
int MakeGnT(int gin, int tonic, int cubes, int slices)
{
return gin + tonic + cubes + slices;
}
And you create a "Normal" G&T by calling it with the first set of ingredients:
int drink = MakeGnT(50, 200, 2, 1);
Or a weaker one by passing different numbers:
int drink = MakeGnT(25, 200, 2, 1);
Or a V&T:
int drink = MakeGnT(0, 200, 2, 1);
The function itself doesn't change, but the resulting drink does.
You have created your function, but you need to pass it the appropriate values for it to do anything useful.
I'd also suggest that you should change your names:
rent
should probably be
RentalAgreement
,
logic
should probably be something like
GetPrice
and so on - make the names reflect what they are there for, what they do instead of "generic" names! Similarly, the parameter names need to reflect what they are there for:
a
is
age
,
c
is
Manufacturer
,
mn
is
ModelNo
- that way when you look at the function you know how to use it.
And the whole class should be independent: move the
takedata
code into the main function so that the class isn't dependant on the environment in which your code is running:
main
"knows" this is a console app, but the rental agreement doesn't so main can use
cin
and
cout
but your new class shouldn't need to know that at all!