removing a number from an arry

Discussion in 'C++' started by cpulocksmith, Jul 3, 2009.

  1. cpulocksmith

    cpulocksmith New Member

    Joined:
    Jul 23, 2008
    Messages:
    289
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    student
    Location:
    canada
    ok, i need some help on a problem i am having. i think this should be an easy one for you guys to figure out but my feeble brain cannot come up with it and anything i found using google has failed me so here it is.
    i want to out put an arry on numbers then have you select one. one that number is selected i want the program to loop and out put the same batch of numbers, but i want it to leave out the number that was selected. here is what i have.

    Code:
        
        //local variables
        int statas;
        int rolled[5];
        char reroll;
        system("cls");
        
           
        rolled[0] = (rand()%16)+3;
        rolled[1] = (rand()%16)+3;
        rolled[2] = (rand()%16)+3;
        rolled[3] = (rand()%16)+3;
        rolled[4] = (rand()%16)+3;
        rolled[5] = (rand()%16)+3;
         
    cout<<"the numbers that will be used for your stats will now be generated \n \n";
    cout<<"1)... "<< rolled[0]<<endl;
    cout<<"2)... "<< rolled[1]<<endl;
    cout<<"3)... "<< rolled[2]<<endl;
    cout<<"4)... "<< rolled[3]<<endl;
    cout<<"5)... "<< rolled[4]<<endl;
    cout<<"6)... "<< rolled[5]<<endl;
    
    cout<<"\n reroll? y/n... ";
    cin>>reroll;
    cin.ignore();
    
                if (reroll == 'y'){
                           gen();
                           }
                else{
             
             system("cls");
    }
    
    cout<<"now to place them in the stat you disire\n"<<endl;
    
    int x=0;
    for (x = 0; x <= 5; x++)
    cout<<rolled[x]<<endl;
    
    cout<<"str... ";
                  cin>>statas;
    

    so yeah... i want to enter say number 3. so click, i entered 3. i want the third number removed from the "rolled array" so that it will not be repeated the next time around. so any ideas?
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    how about something like
    Code:
    if (x!=entered_num)
      cout<<rolled[x]<<endl;
    
    in the for loop.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice