Issues with arrays

I'm trying to perform various operations on an array

EDIT: I forgot that some people on the internet prefer to ignore obvious things.

1. I need to create an int array with 50 elements. This is not a question, this is a statement so you can understand what int alhpa[50] is and why it's there when you see it.



2. I need to initialize all of the elements to -1. This is not a question this is a statement, it's here so when you see for(int i = 0; i < 49; i++){alpha[i] = -1} you know why it's there and you'll realize that I had to do it this way.



3. I need to print out the first element, this is a statement and when you see the for loop that does this you'll know why it's there.



4. I need to manipulate the 25th element in the array so that it has a value of 62, this is not a question this is a statement, how ever if you've got a better way of doing it I would love to hear your idea (i'm still learning)



5. I need to manipulate the tenth element so that it has a value of the fiftieth^3 + 10 . This is not a question this is a statement, it's here so that you don't ask me why and what the for loop is that performs this operation. If you know a better way to do it I would love to hear your idea...



6.I need to use a for loop to output a component of alpha if it's index is a multiple of 2 or 3 how do I do this? This is a question. ^



7.I need to output the last element in the array, how do I do this?
This is a question ^


8.I need to output the entire array (after having formatted the output) to print 15 elements per line, how do I do this?

This is a question ^

9. I need to use a for loop to increment every other element (the even indexed elements), how do I do this?

This is a question^

10. I need to make another array that will contain the differences between consecutive elements in alpha, how do I do this?

This is a question ^

Yes it's a lot I know and I will apreciate any help with this!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <array>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{ 
	int alpha[50],
		element_1,
		element_25,
		last_element;

	for (int i = 0; i < 49; i++)
	{
		alpha[i] = -1;
		element_1 = alpha[i];

		// initializes all elements to have a value of -1
		
	}



	for (int i = 0; i < 1; i++)
	{
		cout <<"The first element is: " << alpha[i] << endl;  
		// Displays the first element in the array
	}
	


	for (int i = 0; i < 24; i++)
	{
		alpha[24] = 62;
		element_25 = alpha[i]; 
		

		// Sets the 25th element to have a value of 62
	}



	for (int i = 0; i < 49; i++)
	{
		int val = pow(alpha[49], 3) + 10; 

		// Takes the value of the fiftieth element performs the above operation (value of element 50 to the third power + 10)

		for (int j = 0; j < 9; j++)
		{
			alpha[9] = val; 
			/*
				stores the value of val in the 10th element (-1 * -1 * -1 + 10 = 9)
			*/
		}
		

	}



	/*
	for (int i = 0; i < 49 && i % 2 == 0; i++)
	{
		cout << alpha[i] << endl;

		 pseudo code here... while i is less than 50 and if i can be divided by 2 evenly advance i, and print i for each advanced position. 
		 and to be more clear I'm attempting to print the index not the values in the array, so for example if index[4] / 2 = 0; etc..
	}  

	for (int i = 0; i < 49 && !i % 2 == 0; i++)
	{ 
		cout << alpha[i] << endl;
	 
	   pseudo code here... while i is less than 50 and if i can not be divided by 2 evenly ( as in if we have a remainder) advance i, and print i for each advanced position.
		and to be more clear I'm attempting to print the index not the values in the array, so for example if index[7] / 3 != 0; etc..
	}
	*/


	for (int i = 48; i < 49; i++)
	{
		cout << "\nThe last element is: " << alpha[49] << endl; 
		// Supposed to display the last element, it does not.
		
	} 



	for (int i = 0; i < 49; i++)
	{
		for (int j = 0; j < 15; j++)
		{
			cout << "\t" << alpha[j];
		} 
		cout << endl; 


		/* 
			These two for loops are supposed to print the entire array, but it's also supposed to break down the array so that it prints out 15 values per line 
			It does print print 15 per line but it resets its self and prints the same 15 values each loop.
		*/
	}


	
	
	









	/*
	for (int i = 0; i < 50; i++)
	{
		cout << alpha[i] << endl;
	}

	*/

	
	return 0;
}


That's only part of what I need to, I've not yet finished all the problems I outlined above this is just a starting point.
Last edited on
You forgot to ask a question.
The questions are at the top please read every thing, they've been there from the start.

The source code clearly points out in the comments ( the /* */ ) What was done in each loop and if it was done right/wrong.

I'm sorry if you can't understand that but it's pretty clear, allow me to edit my code and make it easier to understand!
Last edited on
EDIT
@OP just edited his main post and changed his list, adding "How do I do this" and questionmarks. I thought he would do something like this so I took a screenshot, this is what it looked like to begin with - https://gyazo.com/3e469be72c20f45469fb6e94ed11b83d

Stop playing your stupid games @OP. Make it easier for us to help you instead.

The questions are at the top please read every thing, they've been there from the start.

Im sorry, but you need to look up the definition of question. I don't see a single questionmark used. Those are your 10 needs, as they all start with "I need" followed by a description of what you need.

Edit:
We can clearly see that you need stuff done, that is however not a question. You need to be specific, what exactly do you want. Do you want us to review your code? Are you having trouble understanding certain part of the instructions? What parts in that case?

Last edited on
Hey there yes I did edit it. You can see the EDIT.

Look mate I get it you're being rude because you're having a bad day I get it, it happens to every one.

I'm glad you linked my original thread because to any one other then a two year old it's pretty obvious whats being asked.

The only type of person that would make the comment you made is a troll, a person that's having a bad day and wants to be rude on the internet lol.

I could have been rude and replied, you forgot how to read ( because you know it's hard to read and understand things)

but I didn't because you knew exactly what I was asking, and instead of replying with some thing helpful you chose to be rude.

So I'll just move along and forget entirely about this site so that I don't have to deal with people that have trouble reading or cry about grammar.

EDIT: again.

I'm sorry you're having a bad day perhaps if you change your attitude people may be nicer to you or if nothing else you may brighten some one else's day, any way I do hope you have a better day!
Last edited on
Edit: I love how you're just assuming that I'm having a bad day and that is why Im being "rude". I simply told you that you forgot to ask a question, which you did. Your reply after that was rude. What you did is throw 10 things at us, without any further information. You never told us what your problem was, so we couldnt know what you needed help with, and as it turned out it was not all 10 of the things, we know that now because my comments made you edit it and clarify that. And no, Im not havinga bad day at all. You can see that in all the other threads Ive helped today.

Please stop being rude when All Im trying to do is help you out. Thank you.

I'm sorry you're having a bad day perhaps if you change your attitude people may be nicer to you or if nothing else you may brighten some one else's day, any way I do hope you have a better day!
At this point you don't even deserve any of my help. But Im gonna do it anyway.

I'll continue to edit this thread with help.

For 6. You can use the modulus operator.

1
2
3
4
5
6
7
8
for(int i = 0; i < 49; i++)
{
    if(alpha[i] % 2 == 0 ||alpha[i] % 3 == 0)
    {
         // output a component
    }
 // how modulus work - http://www.cprogramming.com/tutorial/modulus.html
}


For 7. This one is pretty simply. You know all your values is in alpha[0-49]. So the last one is simply alpha[49].

For 8. You're already done something similar. All you have to do is loop through the entire array like you do here -

1
2
3
4
5
6
for (int i = 0; i < 49; i++)
	{
		alpha[i] = -1;
		element_1 = alpha[i];
		// initializes all elements to have a value of -1
	}


But instead just std::cout the element.

1
2
3
4
for (int i = 0; i < 49; i++)
	{
	     cout << alpha[i] << " ";
	}


for 9. Similar to 6. In the link I provided there, it shows how to check whether a number is even or odd. Simply loop through the array, use an if statement to check if it's even. If it is, just add 1 to it.

for 4. Same as number 7. There you print out the last element. Here you simply have to change the 25th element to the value 62. You know the array goes from 0-49, so you should know which one is the 25th element.
Last edited on
I didn't read the entirety of the first post because is was long and rambling, and I got bored.

But I did read the first 2 points. My question is, if you have a 50-element array alpha[0] - alpha[49], why are you only populating alpha[0] - alpha[48]?


Topic archived. No new replies allowed.