Hi, I'm sorta new to c++ I've tried messing around with java but I like c++ better for it's speed. I think the reason why I'm still a newbie at this is because I can't grasp the scientific concept of the syntax. But enough small talk......

I can't seem to find how to fix this program????
(I've googled and searched for hours on this subject)
I'm trying to query 10 numbers then output all the numbers back. It works but not like a query.
I just don't understand what I'm doing wrong I'm sure I'll kick myself once I get it sorted out.

here's my code:

#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int i, numEntered;
    int number[10];
    
    for (i = 0; i <= 9; i++)  
    {
     //--Here's where I think the problem is
        cout<<"Number: ";
        cin>>numEntered; //Ask for  a number
        numEntered = number[i];
    }
   
    cout<<"Numbers entered: "<< numEntered<<endl;   //output 10 inputed numbers
    
    system("pause");  //Pause the screen so one can see the result
    return 0;
}

It gives me some weird output like a string of numbers like... 1988145407.

I'd really like to know the reason for the bug.

Thanks in advance.....

Recommended Answers

All 3 Replies

cin >> numEntered; //Ask for a number
                                 //This part is fine, you get a number from the user

numEntered = number[i]; //oops, it's backwards
                                         //should be number[i] = numEntered instead

Currently your code says:
numEntered is some user input
numEntered is some uninitialized data... when you want to be initializing your data instead.

Also, this is wrong:
cout<<"Numbers entered: "<< numEntered<<endl; //output 10 inputed numbers

numEntered will only be the last number that you entered. Your array is where you are storing 10 numbers. So you'll need another loop.

for (int i = 0; i < 10; i++)
{
   cout << number[i] << endl;
}

Yeah here's where I say a big huge DOH!!! and Very kind thank you I'm actually practicing all the functions of a console cash register I need to learn array queries and file I/O

but thanks again!!! This helped a whole lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.