
November 30th, 2012, 04:38 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 1
Time spent in forums: 26 m 29 sec
Reputation Power: 0
|
|
|
Memory & arrays - Homework help :/
First time here so go easy
Here's the instructions for my homework :
Write a program that inputs 10 integers from the user into an array, and removes the duplicate array elements. By removing, I meant that you should make it appear as if the elements hadn't been there. So not just setting duplicates to an "empty" value, but filling in the gap. That means moving all the later elements back one (kind of like when you hit backspace in the middle of a line in a text editor). Or alternatively, storing only the non-repeating elements. You may assume that all the integers are between 0 and 100, Write at least 1 function in addition to the main function, and pass an array into that function as a parameter.
Here is my code + I am a beginner programmer sorry for blatant errors. The cout<<"yellow" part is just to test to see if the first part of my function is working, which it isnt. Could someone help me get it working and maybe hint at ideas for replacing the duplicate values? Thanks.
Code:
#include <iostream>
using namespace std;
int repeat[10]; void process(int repeat[10]);
void process(int repeat[]) {
int i;
int dup = repeat[1];
{ for(i=0; i< 10; i++)
if(repeat[i] != dup) //checking if repeat[i] is = to dup and if not print repeat[i] than replace dup with repeat[i]
{cout << repeat[i];
dup = repeat[i];}
else cout << "yellow"; }}
int main (void) {
int count = 0;
int input; cout << "Please enter 10 integers, hitting return after each one: \n";
for (; count<10; count++)
{cin >> input; }//input from user
process(repeat);//call statement
system ("pause"); }
|