I cant figure out how to finish this assigment =\
Help >.<

Hm.. Sry for the other language used in it =\
This is the language we are being taugh in >.<'

Cik skaitlu ivadiisiet? = How many numbers to enter?
Ievadiet skaitlus = entered numbers
Ievadiitais masiivs = entered array
Cik skaitlu iznjemt no massiva? = How many number to take away from the array?
Iznjem = taken
massivs = array
garums - lengh


I know i might not amazing with arrays, but i think i did the job correct, sloppy but works xD
Anyways, need help with how gettin the following 2 lines...

1) The numbers you took from the array : ... .... .... ....
2)The numbers left in the array: .... ... ... ... (the trick for the 2nd one is they need to be in ascending order >.>)

#include <iostream>
using namespace std;

void printarray (int arg[], int length) {
  for (int n=0; n<length; n++)
    cout << arg[n] << " ";
  cout << "\n";
}


int main()
{
    int garums = 0;
    int sk;
    int *mass;
    int iznsk, izn;
    
    cout << "Cik skaitlu isvadiisiet? ";
    cin >> garums;
    cout << endl << endl;
    
    mass = new int [garums];
    if (*mass == 0)
       cout << "Error!" << endl;
       else{
    
    
    cout << "Ievadiet " << garums <<" skaitlus - ";
    for(int i=0; i<garums; i++){
            cin >> mass[i];   
    }
    
    cout << endl <<"Ievadiitais masiivs: ";
    printarray (mass, garums);
    cout << endl;
    
    cout << "Cik skaitlu iznjemt no massiva? ";
    cin >> iznsk;
    
    
    for (int j=0; j<iznsk; j++){
        cout << "Iznjem ";
        cin >> izn;
        cout << endl;
        
        for (int k=0; k<garums; k++){
        if (mass[k] == izn)
        
        for(int l=k ;l<garums; l++){
        
        mass[l] = mass[l+1];
        
        
        }
        }
        
    garums = garums -1;
    printarray (mass,garums);}
             
    
    
}
    system("PAUSE");
    return 0;
}

Can you please specify your problem a little bit better? Are there errors? What is the expected output vs the current output?

The assigment is using dinamic arrays.
1)ask how many numbers - DONE
2)enter+show the numbers - DONE
3)Ask and enter how many numbers of thos eu want to remove - DONE
4)ask which number to remove -> remove it -> show the array without the number X how ever many times u said in 3) - DONE

Well, i dont think there are any errors, the thing i dont get is how to get the output properly of the following:

5)The program shows you the numbers that you have selected to remove. - ??????
6) The program shows the numbers that are left, but in ascending order, dont rly know how to make an array show them in ascending order.

(suck with arrays).....

Example of how it should look:

How many number do u want? 8
Enter 8 number : 13 1 44 66 11 3 13 15
entered numbers : 13 1 44 66 11 3 13 15

How many numbers to remove? 3

Select a number to remove: 66
Numbers left: 13 1 44 11 3 13 15

Select a number to remove: 44
Numbers left: 13 1 11 3 13 15

Select a number to remove: 15
Numbers left: 13 1 11 3 13

Numbers you removed: 66 44 15 <------- Havent gotten it to work right
Numbers Left in the array: 1 3 11 13 13 <---- How to make them ascending?

Ok, i think i get how that works. Just 1 question about it.

http://www.cplusplus.com/reference/algorithm/sort/
theres an example:
and

int myints[] = {32,71,12,45,26,80,53,33};
  vector<int> myvector (myints, myints+8);

the +8 in the 2nd line, if i have 4 numbers, then +4?
and also

sort (myvector.begin(), myvector.begin()+4);

the +4, so liek take half of the number u have?
and so on after that....


And other wise, does it seem sloppy, like i have too many extra functions and steps? or this this half decent? ^^

Edited 6 Years Ago by Crow13: n/a

NM! Thx a lot!

Figured it out ^^
Gotta love this site ^^

This article has been dead for over six months. Start a new discussion instead.