-3
#include<iostream.h>
void main()
{
    int i[10], sum, n1, n2, size;

    cout<<"Enter size array :";
    cin>>size;

    for(i=0; i<size; i++)
    {
      cout<<"Enter number 1 :";
      cin>>n1[i];
      cout<<"Enter number 2 :";
      cin>>n2[i];
      sum[i]=n1[i]+n2[i];
    }

    cout<<"sum : "<<sum;
}

i have no idea. please help me . it also stated there Lvalue required in function main.

  • 4
    `n1` is an `int` and you're trying to index it. Also worth noting `` isn't a standard header and it should be `int main`. – chris Feb 14 '14 at 03:33
  • sum, n1 and n2 are not arrays. Also, are you using Turbo C++? –  Feb 14 '14 at 03:33
  • related concerning [iostream](http://stackoverflow.com/questions/214230/iostream-vs-iostream-h-vs-iostream-h) and concerning [type returned by main](http://stackoverflow.com/questions/214230/iostream-vs-iostream-h-vs-iostream-h) (look at the bold part of the answer) if you want to know more about what chris meant – AliciaBytes Feb 14 '14 at 04:00
  • @remyabel _'Turbo C++'_ **Brrrr! Choke! Cough!!!** (`#include` is a pretty good indicator) Why do we see this so often here (especially from beginner students)?? Is there a major problem migrating university personal to nowadays compiler standards?? – πάντα ῥεῖ Feb 14 '14 at 04:04
  • im a beginner. oh i get it. thank you! – user3308705 Feb 14 '14 at 04:34

2 Answers2

2
int i[10], sum, n1, n2, size;

You declare i to be an array, but you use it like it's a single value. You try to index sum, n1, and n2 by writing [i] after them in the loop, but they're not declared as arrays.

Recommendation: change your variable declarations.

int i, sum[10], n1[10], n2[10], size;
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
0

I think you have to try this:

#include<iostream>
int main()
{
    int i, sum[10], n1[10], n2[10], size;

    cout<<"Enter size array :";
    cin>>size;

    for(i=0; i<size; i++)
    {
      cout<<"Enter number 1 :";
      cin>>n1[i];
      cout<<"Enter number 2 :";
      cin>>n2[i];
      sum[i]=n1[i]+n2[i];

    cout<<"sum : "<<sum[i] << endl;
    }
}
AliciaBytes
  • 7,300
  • 6
  • 36
  • 47
A B
  • 1,461
  • 2
  • 19
  • 54