Write your question here.
hey guy i am adding arrays when user give input from keyboard,d but the result is different from what i give input... Please sort it out
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
int main()
{
int add[5];
int n, sum=0;
for(int x=0; x<5; x++){
cout<<"Enter Value : " <<endl;
cin >> n;
sum += add[n];
}
cout << sum;
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
constint size = 5;
int add[size];
// Get the input and store it
for (int x=0; x<size; x++)
{
cout<<"Enter Value : " << x+1 << endl;
cin >> add[x];
}
// calculate the total of the values in the array
int sum = 0;
for (int x=0; x<size; x++)
{
sum += add[x];
}
cout << "Total = " << sum;
return 0;
}