0
What is wrong with the code? Pleeeaase
So i don't really know if the code is wrong or my codeblock. When i'm inputing numbers in the array i can input less than 31 numbers. Although the asnwer which it gives me is right. #include <iostream> using namespace std; int main (){ double arr[31]; int k; int br=0; for (int i; i<31; i++){ cin>>arr[i]; } cout<<"input k"<<endl; cin>>k; for (int x; x<31;x++){ if (arr[x]==k) br++; } cout<<br; return 0; }
3 Answers
+ 1
Your code should work if you write int i = 0 in the first loop condition and int x = 0 in the second.
+ 1
Thank you so much! I told it's going to be a dumb mistake such at is. I'm new to this stuff.
0
Деян Милчев
Your welcome.
Maybe this article is helpful for you: https://www.learncpp.com/cpp-tutorial/uninitialized-variables-and-undefined-behavior/



