Friday, March 27, 2026

Lesson 3: Loops - pt.1 (for, arrays)

In our earlier lesson, we asked the user for 3 values, corresponding to each side of a triangle. It was quite repetitive.

std::cout << "enter side a: "; std::cin >> a; std::cout << "enter side b: "; std::cin >> b; std::cout << "enter side c: "; std::cin >> c; // boringg

But programmers do not like to waste time and effort if not needed...What if I told you I could summarize this in 4 lines:

double side[3]; // an array for (int i = 0; i < 3; i++) { std::cout << "enter the side " << i + 1 << ": "; std::cin >> side[i]; }

I imagine it must be pretty confusing to read this, and that's very normal. I have yet to introduce you to loops and arrays!! 

mint yoongi and orange jimin

Let's break it down. But before, I'd like you to check by yourself how it works.