Why is this code not working well | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is this code not working well

Array- for loop https://code.sololearn.com/conYo43U2PPd/?ref=app

14th Nov 2020, 1:48 PM
Anas kayani
Anas kayani - avatar
13 Answers
14th Nov 2020, 2:06 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 7
What is ur expected output
14th Nov 2020, 1:56 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 7
variable x is declared 2 times
14th Nov 2020, 2:00 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 7
Jayakrishna🇮🇳 That's not enough... He also has to specify array size ,otherwise the Sum doesn't give the expected output..
14th Nov 2020, 2:28 PM
Alphin K Sajan
Alphin K Sajan - avatar
14th Nov 2020, 2:33 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 3
All? Is the question solved?
16th Nov 2020, 9:58 AM
Кайто Судзуки
Кайто Судзуки - avatar
+ 1
Sum of array is also missing
14th Nov 2020, 1:56 PM
Anas kayani
Anas kayani - avatar
+ 1
The sum of all the given numbers present in array
14th Nov 2020, 1:58 PM
Anas kayani
Anas kayani - avatar
+ 1
https://code.sololearn.com/cYba72GcejZN/?ref=app Now it is still causing problem Can u send me the correct code
14th Nov 2020, 2:03 PM
Anas kayani
Anas kayani - avatar
+ 1
#include<iostream> using namespace std; int sum=0,x; int main() { int arr[]={1,3,5,9,5,7,0,8}; //you are missing braces for loop, if you dont provide then only next 1 statement comes into a loop, so sum+=arr[x] will not part of loop. for(int x=0;x<8;x++) { cout<<"print number "<<arr[x]<<endl; sum+=arr[x]; } cout<<"\nsum = "<<sum<<endl; return 0; } Edit : for finding array size in c/c++, you can use this formulae : int size= sizeof(arr)/sizeof(arr[0]); So now instead of use size as x<size;
14th Nov 2020, 2:26 PM
Jayakrishna 🇮🇳
+ 1
Alphin K Sajan anas kayani for finding array size in c/c++, you can use this formulae : int size= sizeof(arr)/sizeof(arr[0]);
14th Nov 2020, 2:31 PM
Jayakrishna 🇮🇳
+ 1
Yes
16th Nov 2020, 11:49 AM
Anas kayani
Anas kayani - avatar
0
Ok thanks
14th Nov 2020, 2:53 PM
Anas kayani
Anas kayani - avatar