Someone can help with this LOOP problem in C++ ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Someone can help with this LOOP problem in C++ ?

Hello , I have this code and program must run and calculate the product of the elements on odd positions in the vector and must stop when user enter value 0 but the program ends aften i enter 2 values. #include<iostream> using namespace std; int main() { int v[100], i, p; cout << "Introduceti primul element al vectorului "; cin >> v[0]; if (v[0] != 0){ p = 1; i = 1; do { cin >> v[i]; if (v[i] % 2 != 0){ p = p * v[i]; } i++; } while (!(v[i] != 0)); } else { p = 0; } cout << p; return 0; } This is the code. https://code.sololearn.com/cqWdTZ7v9nfm/#cpp Someone can help me to solve this problem. Thanks.

19th May 2020, 4:25 PM
Joita Vladut
Joita Vladut - avatar
1 Answer
+ 1
The SoloLearn environment only allows user input one time at the beginning when you run the program. You can enter multiple values on separate lines, but once the program is running there's no way to enter input again (like repeatedly from within a loop).
19th May 2020, 5:37 PM
Ralphie
Ralphie - avatar