loopy loopy loops
Assume the int variables i, lo, hi, and result have been declared and that lo and hi have been initialized. Write a for loop that adds the integers between lo and hi (inclusive), and stores the result in result. Your code should not change the values of lo and hi. Also, do not declare any additional variables -- use only i, lo, hi, and result.
result = 0; for (i >= lo && i <= hi; i++;) { result += i; }
Lemme open visual studio real qucik
quick*
```cpp int result = 0; ``` You forgot to identify the datatype
Ah, didn't realize it already defined it
the stuff in black is what they did, but they don't show us that before we attempt the question at all
Ah
K finally got my visual studio setup lol
-still figuring this out-
I would think it would be ```cpp i = lo; for (i >= 5 && i <= 10; i++;) { result += i; } ``` but the loop isn't ending for some reason
so I'm sitting here scratching my head at that
unless I'm mistaking the logic should be fine :thinking_face:
sorry, brother needed me
maybe something along the lines of this? result = 0; i = lo; for (i <= hi; i++) { result += i; }
got it, was on the right train of thought with that last idea
there ya go =P
Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a do...while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total. Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total. Use no variables other than n, k, and total.
total = 0; do { total += k*k*k; k++; } while(n >= k);
```cpp int total = 0; do { total += k*k*k; k++; } while(n >= k); ```
total was already declared as an int
did it just so it would show the full code lol
got it
Join our real-time social learning platform and learn together with your friends!