Before we start, did you try solving the workbook yourself?
If not, please click the link in the resources folder and follow the instructions for this workbook.
The workbook contains an array that stores for prices can confirm.
All right.
Create another array after tax with the same length.
So here we can say double.
After tax is equal to a new array that can store values of type double.
The length of the array is four.
As you can clearly see, but I encourage you to put price dot length instead.
It's better practice and you might be thinking why?
Well, when you do it that way, it's more loosely coupled, right?
Because let's say I add two more elements.
Price length will still reflect the length of the array, but if initially it was four, I would have
to change it to six.
So it's always good to make sure that your code is loosely coupled.
For that reason, it's better to reference the length of the array.
All right, enough about that task too.
So tax apparently is 13%.
Use a loop to update each element and after tax to equal the original price plus tax.
All right, simple enough.
So I'll create a for loop where I starts at zero, because after tax is always going to have the same
length as price.
We can use either of their lengths for our condition.
I Plus.
So this loop is going to keep running so long as AI is smaller than the length of our array.
And for every element that we go through, we're going to set that element equal to its corresponding
price element plus that same price.
Times the tax.
All right.
And now use arrays to string to print the arrays.
I'm really glad that's the case because I don't feel like making another for loop arrays to string.
Here we print the original prices.
And here we print the prices.
After tax.
Beautiful.
Put a breakpoint right here.
So here, price stores four elements.
Oh, sorry.
This wasn't, I guess six.
I forgot to remove these too.
Anyways, does it matter?
And after tax was initialized to have the exact same length.
So it also has six elements.
By default, they're all zero, so we need to start updating them here.
The for loop starts at I equals zero.
When I equals zero, the original price is $1.99.
So the after tax price at index zero is going to equal the original price plus the tax.
Beautiful.
Now I equals one.
The original price at index one is 299 and we're setting the element at index one of after tax equal
to 2.99 plus tax.
Splendid.
Now I equals to the original price.
There is 3.99.
We're setting the element that index to of after tax equal to 3.99 plus tax.
We keep doing that until the loop eventually runs to completion.
The original prices are the following.
And the after tax prices are those.
And we're done.