Hello,
I've copied a multiarray into another multiarray and can't figure out how to convert an int of 1 into an asterik which is ascii 42 I believe. I need help to replace all 1's to an asterik. I've tried static cast which my instructor suggested but I must be doing it wrong, it didn't work and I tried numerous ways.

offScreenArray[row][col] = onScreenArray[row][col];
 while(offScreenArray[row][col] == 1)

	  
	 offScreenArray[row][col] = static_cast<char>('*');

Recommended Answers

All 9 Replies

What are the types of both arrays?

Also, the way you have it laid out if you hit a 1 on the first pass through the while you'll get stuck there (unless you are incrementing row and col somewhere else).

What are the types of both arrays?

Also, the way you have it laid out if you hit a 1 on the first pass through the while you'll get stuck there (unless you are incrementing row and col somewhere else).

They are int type arrays. The loop works I have it set for 1 loop now while I'm building it that is just the snippet of my problem area. I have the 2 arrays copied and printed right now but the 1's are a problem. I can convert the 1's to ascii 42 but I want the asterik.

What are the types of both arrays?

Also, the way you have it laid out if you hit a 1 on the first pass through the while you'll get stuck there (unless you are incrementing row and col somewhere else).

I see what you mean about getting stuck, I guess I need an if statement in place of the while?

Why not copy it all over to a char array, substituting the '*' for and integer value of 1 and converting all other integer values to characters (assuming they are all one digit)?

I mean technically chars are integers so you could store you asterisks as 42 in the int array but then your 1 values would have to be 49 to remain consistent. If you were to try to output the array by casting it your 1's would end up as a non-printing character.

Why not copy it all over to a char array, substituting the '*' for and integer value of 1 and converting all other integer values to characters (assuming they are all one digit)?

I mean technically chars are integers so you could store you asterisks as 42 in the int array but then your 1 values would have to be 49 to remain consistent. If you were to try to output the array by casting it your 1's would end up as a non-printing character.

Ok, I'll give it a try and yes my values are either a 1 or a 0 and the 1 needs to convert an asterik but not the 0. Thank you! I'll let you know what happened.

Ok, I'll give it a try and yes my values are either a 1 or a 0 and the 1 needs to convert an asterik but not the 0. Thank you! I'll let you know what happened.

Hey, it worked! Thank you! Another question if you don't mind? I'm generating random numbers between 0 and 1. Is there a way that I can generate more 1's then 0's? Or, is this not possible?

Are you drawing numbers in between 0 and 1 or just 0 and 1 themselves? I'm not sure about biasing the selection. I suppose,for example, you could generate a random floating point number between 0 and 1 and if it's greater than .33 output a 1 and less than that make it a zero. That would give you roughly twice the number of 1s.

However, I'm certain there's someone that has dealt with this more than I have and so I don't guarantee this to be an ideal solution and there's definitely a better way.

In the meantime check out Narue's great tutorial on the subject: http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx

Are you drawing numbers in between 0 and 1 or just 0 and 1 themselves? I'm not sure about biasing the selection. I suppose you could generate a random floating point number between 0 and 1 and if it's greater than .33 output a 1 and less than that make it a zero. I'm certain there's someone that has dealt with this more than I have and so I don't guarantee this to be an ideal solution.

In the meantime check out Narue's great tutorial on the subject: http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx

Just 0 and 1 but doesn't seem like a whole lot of 1's appear but oh well if they don't. I'll check the link you suggested. Thanks again you've been a big help! I'll mark this thread as solved which brings me to another question, I've marked my past 2 threads as solved but my screenname shows as 0 solved threads? Does it mean that I haven't solved someone elses threads? Maybe I should direct this question to the site admin? Thanks again!

Yeah getting a steady distribution of 0s and 1s is difficult. I wish I could elaborate more on the theory about that but I believe it has something to do with the lower order bits problem that Narue describes.

Solved threads is how many of your posts on other people's threads that end up being solved. So, as it stands anyone that has posted on that thread (besides the OP) before it was marked gets credit.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.