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; }

6th Apr 2020, 10:45 AM
Деян Милчев
Деян Милчев - avatar
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.
6th Apr 2020, 10:57 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thank you so much! I told it's going to be a dumb mistake such at is. I'm new to this stuff.
6th Apr 2020, 11:00 AM
Деян Милчев
Деян Милчев - avatar
6th Apr 2020, 11:13 AM
Denise Roßberg
Denise Roßberg - avatar