array not displaying values

This is a discussion on array not displaying values within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; const int MAX=100; int elems[MAX]={1,2,3}; int card=3; void Rem(const int e); void Rem(const int ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    24

    array not displaying values

    Code:
    #include <iostream>
    using namespace std;
    
    const int MAX=100;
    int elems[MAX]={1,2,3};
    int card=3;
    
    void Rem(const int e);
    
    void Rem(const int e) {
    	for (int i=0; i<card; i++) {
    		if (elems[i]==e) {
    			for (;i<(card-1); i++) {
    				elems[i]=elems[i+1];
    			}
    			card--;
    		}
    	}
    }
    
    int main() {
    	Rem(2);
    	for (int i; i<card; i++) {
    		cout << elems[i];
    	}
    }
    this doesnt display anything. wats wrong

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,619
    I notice that in main, you did not initialise i.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    24
    Quote Originally Posted by laserlight View Post
    I notice that in main, you did not initialise i.
    THank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Displaying Values...
    By vailant in forum C Programming
    Replies: 35
    Last Post: 01-21-2010, 05:59 PM
  2. Replies: 12
    Last Post: 04-12-2009, 05:49 PM
  3. Displaying highest and lowest values
    By beastofhonor in forum C++ Programming
    Replies: 3
    Last Post: 10-29-2006, 07:24 PM
  4. Displaying values from one class in another...
    By Dan17 in forum C++ Programming
    Replies: 2
    Last Post: 02-03-2006, 06:36 AM
  5. need some advice on displaying values
    By rEtard in forum Windows Programming
    Replies: 7
    Last Post: 06-16-2005, 09:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21