Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a new Computer Science student and my professor won't teach but left us homework that needed to be pass tomorrow at 6 am.

Make a program that use 1D array, looping and comparing each element.

Original Element of array: 3 5 3 2 7 10 15 15 2 51
Unique Element of array: 3 5 2 7 10 15 1

My problem is that, only the unique element has answers.
This was the result:


original elements of the array:
unique elements of the said array: 3 5 3 2 7 10 15 15 2 5 1

What I have tried:

C++
#include <iostream>
using namespace std;
int main ()
{
    int i;
    int num [11] = {3,5,3,2,7,10,15,15,2,5,1};
    cout <<"original elements of the array: ";
    
    cout <<"\nunique elements of the said array: ";
    for (i=0; i<11; i++)
    {
    cout<
Posted
Updated 24-Apr-21 5:18am
v6
Comments
Patrice T 24-Apr-21 11:19am    
Part of your code is missing.
Shroudpewds Taco 24-Apr-21 11:27am    
Huh? Can you tell me what is it? I have no clue. 😬
Patrice T 24-Apr-21 11:36am    
The end is missing.
your cade can't end on last line in question

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
Shroudpewds Taco 24-Apr-21 9:41am    
Oh, ok. Thank you! The problem is that my teacher won't teach and told us that learn the things by our own. He might be right. I'll try to understand books then. I'm sorry.
OriginalGriff 24-Apr-21 9:58am    
The problem is that you don't really learn this stuff without actually doing it - it's a skill, not "rote knowledge" and like all skills it only develops and improves as you use it.
So us just solving the code for you teaches you nothing - making the next task even harder, since it builds on your "previous knowledge" which you don't have!
Shroudpewds Taco 24-Apr-21 10:15am    
Calm down Mister. I might be stupid, I admit. But please, I don't want you to get mad and disrespect me. You can just ignore it. I was just seeking help. I really don't have skills on computer. So if you are an expert, I hope to be like you.
OriginalGriff 24-Apr-21 11:15am    
What gives you the idea I',m annoyed?
If I camer over that way, I'm sorry - it wasn't intended like that at all.

I know you are a beginner, and that we all start somewhere - but you really don't learn this stuff without doing it, like any skill.
For example, you can read all the books, watch all the videos on how to ride a bicycle, but that won't help you ride it, because you don't have the skill; the sense of "continuous little movements" to keep yourself upright. You get that by ... getting on a bike and eventually not falling over :D

Development is the same: remembering the syntax is the easy bit - working out how to use it isn't something you can "get" from a book or video.

Give it a try: make mistakes, and learn from them. That's what we all did / do!
Shroudpewds Taco 24-Apr-21 11:25am    
I understand. I'm so sorry. 🙏
See Arrays - C++ Tutorials[^]. If your teacher tells you to learn things for yourself then you should go for the better websites, such as this one I suggested. But don't waste your time with YouTube videos; many of them are incorrect, or just poor quality.
 
Share this answer
 
Comments
Shroudpewds Taco 24-Apr-21 10:03am    
Thank you very much! I'm sorry if I look desperate. I just really need help. You are so amazing!
Richard MacCutchan 24-Apr-21 10:18am    
All I did there was use Google to find an explanation of arrays in C/C++. Something that you would do well to get used to doing for yourself.
Quote:
C++ how do I make a program that use 1D array, looping and comparing the elements?

It is not your first C program.
- At least get started with the standard empty minimum skeleton.
- Declare the first array.
- Add a loop that will every element of array.
Quote:
Original Element of array: 3 5 3 2 7 10 15 15 2 51
Unique Element of array: 3 5 2 7 10 15 1

Guessing you want to remove duplicates, but example have error.
Try to do the job by hand, how do you proceed ?
This is the base of your algorithm and your program.
 
Share this answer
 
Comments
Shroudpewds Taco 24-Apr-21 10:08am    
Thank you very much! I'll try to do it step by step, by your help. As a student, I wish you could be my professor.
Patrice T 24-Apr-21 10:12am    
For further help, show your work and explain where you are stuck.
Use Improve question to update your question.
Richard MacCutchan 24-Apr-21 10:17am    
Oops.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900