Зміст курсу
Introduction to C++
Introduction to C++
Challenge
Let's practice!
Swipe to show code editor
Lily went to the shop to buy some clothes. It was the sales day so all the clothes she bought were at discount. Let’s calculate the total discount she got.
We have two arrays of the same length (6): prices and sales. The first array stores prices (in dollars) for Lily’s clothes and the second one stores discounts (in percent, 0.1 means that the thing has a 10% discount) for the corresponding clothes.
You should:
- Use for loop to go through the arrays, don't forget to open curly brackets.
- Calculate the discount for each thing by multiplying the corresponding elements of two arrays and store the result in the variable
discountForEach
.
- To find the sum of all discounts, add variables
discountForEach
andtotalDiscount
, and store the result in the variabletotalDiscount
.
- Close curly brackets.
- Print the variable
totalDiscount
.
Please, don’t forget to type the semicolon at the end of the lines.
Дякуємо за ваш відгук!
Challenge
Let's practice!
Swipe to show code editor
Lily went to the shop to buy some clothes. It was the sales day so all the clothes she bought were at discount. Let’s calculate the total discount she got.
We have two arrays of the same length (6): prices and sales. The first array stores prices (in dollars) for Lily’s clothes and the second one stores discounts (in percent, 0.1 means that the thing has a 10% discount) for the corresponding clothes.
You should:
- Use for loop to go through the arrays, don't forget to open curly brackets.
- Calculate the discount for each thing by multiplying the corresponding elements of two arrays and store the result in the variable
discountForEach
.
- To find the sum of all discounts, add variables
discountForEach
andtotalDiscount
, and store the result in the variabletotalDiscount
.
- Close curly brackets.
- Print the variable
totalDiscount
.
Please, don’t forget to type the semicolon at the end of the lines.
Дякуємо за ваш відгук!