Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 user inputing values of an array
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
marcus




PostPosted: Mon Jul 02, 2012 12:05 am   Post subject: user inputing values of an array

I want to write a program which allows a user to enter the values of an array using a for loop, however I am getting an error which says "name lookup of x changed for ISO 'for' scoping"
i am new to C++ (two weeks) and i have NO clue what this means. here is my code

code:


#include <iostream>

using namespace std;

int array[3];

int main()
{
    for (int x = 0 ; x <=2 ; x++)
    cout <<"Enter an integer ==> ";
    cin >> array[x];

}


thanks in advance for any help[syntax=""][/syntax][syntax=""][/syntax]
code:
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Jul 02, 2012 12:15 am   Post subject: RE:user inputing values of an array

The problem is that for line
code:

cin >> array[x];

variable x does not exist (it was never declared in the current scope).

http://en.wikipedia.org/wiki/Scope_(computer_science)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: