Allow user to input 10 numbers and store the numbers C++

3397 views c++
0

I tried this code but this is not working I'm getting Undefined symbols for architecture x86_64:

#include<iostream>
#include<curses.h>
int main()
{
    int i, a[10], s = 0;
    std::cout<<"Enter 10 variables -";
    for (i = 0;i<10;i++)
    {
        std::cin>>a[i];
    }
for (i = 0;i<10;i++)
{
    s = s + a[i];
}
std::cout<<"Sum = ";
getch();
    return 0;
    } 

answered question

I suspect your problem is covered by stackoverflow.com/questions/12573816/…

@Nelson Be careful when pasting in your code. It's hard to read with the indentation as it is. Are you including curses.h just to have getch() available?

1 Answer

12

Try the following:

#include<iostream>
#include<curses.h>
int main()
{
    int i, a[10], s = 0;
    std::cout<<"Enter 10 variables -";
    for (i = 0;i<10;i++)
    {
        std::cin>>a[i];
    }
    for (i = 0;i<10;i++)
    {
        s = s + a[i];
     }
     std::cout<<"Sum = "<<s;
     getch();
     return 0;
} 

posted this

Have an answer?

JD

Please login first before posting an answer.