Thread: change element in array

  1. #1
    Registered User
    Join Date
    Nov 2014
    Posts
    4

    change element in array

    excuse me there,
    sorry for your time,
    how can i change any element in received array to another number?
    example:
    i want to change 4th element in sent ( 0 ) and change it to ( 1 ) in received

    Code:
    //array
    #include<iostream>
    #include<iomanip>
    using namespace std;
    int main()
    {
      
        int sentArray[ 16 ]={ 0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,1 };
        int receivedArray[ 16 ];
        
       
    
    
        for (int i=0;i<10;i++)
        
         receivedArray[i]=sentArray[i];
        
        cout<<" sent "<<setw(13)<<" received "<<endl;
        
        //output contents of inaaray and outarray in tabular format
        for (int j=0 ; j<10 ; j++ )
        cout<<setw(5)<<sentArray[j]<<setw(13)<<receivedArray[j]<<endl;
        
        
        
        
        system("pause");
    }   //end main

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by izhamzamli17
    how can i change any element in received array to another number?
    example:
    i want to change 4th element in sent ( 0 ) and change it to ( 1 ) in received
    Err... where did you get this code from? You might want to read your learning materials on arrays. I can tell you that your answer lies within the code that you posted:
    Code:
    receivedArray[i]=sentArray[i];
    With the help of your learning material, figure out what that does, then your answer would become obvious to you.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Change one element of string pointed by char pointer
    By Ducky in forum C++ Programming
    Replies: 16
    Last Post: 02-15-2013, 09:29 PM
  2. array of ptrs vs constant ptr to an first element of array
    By monkey_c_monkey in forum C Programming
    Replies: 5
    Last Post: 08-30-2012, 11:39 PM
  3. Replies: 3
    Last Post: 03-16-2012, 04:42 AM
  4. size of an array poited by array element
    By mitofik in forum C Programming
    Replies: 7
    Last Post: 12-24-2010, 12:09 AM
  5. How to add/subtract from array element...
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 05-01-2002, 10:04 PM