• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

usea

Member
Doesn't help that this gig is a 3 month to perm thing. How do you show your worth in that little time when you don't know anything? Be open? Eager to learn type of thing?

Things will hopefully get better over time (They said stuff will take months to get).
I suspect this varies a lot too, but at places I know this is mostly extra insurance for the company against hiring somebody who doesn't end up working out. I was hired the same way out of school, and so was a coworker. But yeah, being eager will help. Also just showing that you're smart or you can get things done. Don't put the bar for yourself too high though. A lot of people in this industry suffer from the inability to recognize their own skills. It's easy to think everybody around you is awesome and you're terrible, but try not to fall into that trap. Just do your best and you'll be fine.
 

Fat Goron

Member
This seems pretty stupid, but how can I (in C) properly use scanf to read an input like "A1 B2;C3 D4"? The idea here is to store in a queue the movements of a piece in a chessboard-like table.
 
This seems pretty stupid, but how can I (in C) properly use scanf to read an input like "A1 B2;C3 D4"? The idea here is to store in a queue the movements of a piece in a chessboard-like table.

Code:
for(i = 0; i < [number]; i++)
    scanf("[insert whatever here"]);

?
Edit: you can also enque each as it's entered.
 

Fat Goron

Member
Code:
for(i = 0; i < [number]; i++)
    scanf("[insert whatever here"]);

?
Edit: you can also enque each as it's entered.

The problem actually is the "insert whatever here". I'm not being able to read a string like "A1 B2; C3 D4" and store each of these coordinates separately. Besides, the user should be able to input any number of movements at once.
 

usea

Member
The problem actually is the "insert whatever here". I'm not being able to read a string like "A1 B2; C3 D4" and store each of these coordinates separately. Besides, the user should be able to input any number of movements at once.
Here is a related question that might help.
http://stackoverflow.com/questions/9599794/putting-numbers-separated-by-a-space-into-an-array

You'll have to make changes, since that person's goal is to only read numbers. But it's good info on reading multiple things from a single line with scanf
 

Relix

he's Virgin Tight™
I need to learn some C#. I am using VB and ASPX for a current project at work but I want to move on to C# for other stuff. Any good books for C#?
 
The problem actually is the "insert whatever here". I'm not being able to read a string like "A1 B2; C3 D4" and store each of these coordinates separately. Besides, the user should be able to input any number of movements at once.

you could try using
Code:
  scanf("%s", &input)  //%s stops reading at the first white space character found
which stops reading whenever it encounters white space. And just add a loop to check that something was read.
 

pompidu

Member
Need some help with this Java lab as my instructor didn't really teach us how to do this. I apologize for the length. Suppose to balance the brackets.
The instructions:
MATCHING Strings
OPEN CLOSED
begin end
[ ]
{ }
( )
(* *)




MATCHING Strings
OPEN CLOSED
<HTML> </HTML>
<HEAD> </HEAD>
<BODY> </BODY>
<BOLD> </BOLD>
<CENTER> </CENTER>

Your Lab Assignment:
• Define a Java interface called Balancer, that has only the public boolean isBalanced(ArrayList<String> list) method.
• Define an abstract class called TokenBalancer that implements the Balancer interface and has
o A public abstract boolean matches(String open, String closed) method.
o An isBalanced(ArrayList<String> tokenList) method. The tokenList is an ArrayList of String objects. It uses a StringStack as a local variable, and uses the matches method.
• Define two classes: PascalBalancer and HTMLBalancer both of which extend the TokenBalancer. Each of these classes must have a public boolean matches(String open, String closed) method and contain code that specifies what matches what.
• Define a BalancerTester class that has the main method and does the following:
o Create an object pb of type PascalBalancer
o Create an object hb of type HTMLBalancer
o Create 5 sets of data for each of the balancers and test the balancers. One sample set of data is provided for each balancer below. Use the same technique to generate another 4 sets of data for each. Make sure that two of the data sets return true and the others return false.

String pasc1 = "begin " +
"a [ 1 ] = 22 * ( 4 + 9 ) ; (* abcd *) " +
" end ";
StringTokenizer stk1 = new StringTokenizer(pasc1," ");
ArrayList<String> pascData1 = new ArrayList<String>();
while (stk1.hasMoreElements()){
pascData1.add(stk1.nextElement();
}

if (pb.isBalanced(pascData1))
System.out.println("pascData1 is balanced!");
else
System.out.println("pascData1 is NOT balanced!");

String html1 = "<html> " + "<head> abcd </head> <body> <bold> " +
" abcd </bold> </body> " + " </html> ";
StringTokenizer stk2 = new StringTokenizer(html1," ");
ArrayList<String> htmlData1 = new ArrayList<String>();
while (stk2.hasMoreElements()){
htmlData1.add(stk2.nextElement();

if (hb.isBalanced(htmlData1))
System.out.println("htmlData1 is balanced!");
else
System.out.println("htmlData1 is NOT balanced!");

Interface:
Code:
package lab7;

import java.util.ArrayList;

public interface Balancer 
{
	public boolean isBalanced(ArrayList<String> list); 
}

AbstractClass which is where I'm completely lost
Code:
package lab7;

import java.util.ArrayList;
import java.util.Stack;

public abstract class TokenBalancer implements Balancer
{	
	public TokenBalancer()
	{
		
	}
	
	public abstract boolean matches(String open, String closed);
	
	public boolean isBalanced(ArrayList<String> tokenList)
	{
		Stack<String> stringStack = new Stack<String>();
		for (int k = 0; k < tokenList.size(); k++)
		{
			
			String list = tokenList.get(k);
			
				if ()
					stringStack.push();				
				else if ()
				{
					if (stringStack.isEmpty())
						return false;
					if (!matches( )
						return false;
					stringStack.pop();
				}
		
		}
			if (!stringStack.isEmpty())
				return false;
			return true;
			}
		}
Html:
Code:
package lab7;

import java.util.ArrayList;

public class HTMLBalancer extends TokenBalancer
{
	public HTMLBalancer()
	{
		
	}
	
	public boolean matches(String open, String closed)
	{
		if (open == "<HTML>"   && closed ==   "</HTML>") return true;
	    if (open == "<HEAD>"   && closed ==   "</HEAD>") return true;
	    if (open == "<BODY>"   && closed ==   "</BODY>") return true;
	    if (open == "<BOLD>"   && closed ==   "</BOLD>") return true;
	    if (open == "<CENTER>" && closed == "</CENTER>") return true;

	    return false;
	}

	
}
Pascal:
Code:
package lab7;

public class PascalBalancer extends TokenBalancer
{
	public PascalBalancer()
	{
		
	}
	
	public boolean matches(String open, String closed)
	{
		if (open == "begin" && closed == "end") return true;
		if (open == "["  && closed ==  "]") return true;
	    if (open == "{"  && closed ==  "}") return true;
	    if (open == "("  && closed ==  ")") return true;
	    if (open == "(*" && closed == "*)") return true;
	    
	    return false;

	}
	
	
}
 

Mangotron

Member
Ok, I got more of my program from earlier to work!

Code:
int isValid(string phoneNumber)

	
{
	int status;
	int first;
	first = phoneNumber.at(0);
	
	if (phoneNumber.length() != 8 && phoneNumber.length() != 11)
	{
		status = 1;
		cout << "Invalid phone number: " << phoneNumber << endl;
		cout << "Your call cannot be completed because:" << endl;
		cout << "A phone number must have 8 or 11 characters" << endl;
		cout << "Please try again." << endl;
	}

	else if(first != 1)
	{	
		status = 2;
		cout << "Your call cannot be completed because:" << endl;
		cout << "A phone number must begin with a 1" << endl;
		cout << "Please try again." << endl;
	}

	else status = 0;
	
	
	return status;
}

So right now it will check and see if the number is 8 or 11 digits long as well as make sure the first digit is a 1.

What I want to do now is check that each number in the phoneNumber string is a digit from 0-9, but I'm not sure how. I know how to do relational operators to check a number against a range, but I'm stumped on how to check each digit individually.
 

pompidu

Member
Ok, I got more of my program from earlier to work!

Code:
int isValid(string phoneNumber)

	
{
	int status;
	int first;
	first = phoneNumber.at(0);
	
	if (phoneNumber.length() != 8 && phoneNumber.length() != 11)
	{
		status = 1;
		cout << "Invalid phone number: " << phoneNumber << endl;
		cout << "Your call cannot be completed because:" << endl;
		cout << "A phone number must have 8 or 11 characters" << endl;
		cout << "Please try again." << endl;
	}

	else if(first != 1)
	{	
		status = 2;
		cout << "Your call cannot be completed because:" << endl;
		cout << "A phone number must begin with a 1" << endl;
		cout << "Please try again." << endl;
	}

	else status = 0;
	
	
	return status;
}

So right now it will check and see if the number is 8 or 11 digits long as well as make sure the first digit is a 1.

What I want to do now is check that each number in the phoneNumber string is a digit from 0-9, but I'm not sure how. I know how to do relational operators to check a number against a range, but I'm stumped on how to check each digit individually.

Try putting it in a for loop and checking each character if its between 0 and 9. Im sure theres a better why but thats off the top of my head.
 
I need to learn some C#. I am using VB and ASPX for a current project at work but I want to move on to C# for other stuff. Any good books for C#?

Haven't read it, but I might suggest Head First C# as an intro. If it's anything like Head First Java, it will be a good primer, if not a little basic at the outset if you have programming experience. Since you already have VB, it's more about just getting the syntax and C# idioms down. You should already know enough about .NET libraries to get you going.
 

Fat Goron

Member
you could try using
Code:
  scanf("%s", &input)  //%s stops reading at the first white space character found
which stops reading whenever it encounters white space. And just add a loop to check that something was read.

I've already tried this as well.... For some reason, the former values get messed up.

Here is a related question that might help.
http://stackoverflow.com/questions/9599794/putting-numbers-separated-by-a-space-into-an-array

You'll have to make changes, since that person's goal is to only read numbers. But it's good info on reading multiple things from a single line with scanf

ffs this wasn't supposed to be such a mess... :lol
but thanks!
 

squidyj

Member
Ok, I got more of my program from earlier to work!

Code:
int isValid(string phoneNumber)

	
{
	int status;
	int first;
	first = phoneNumber.at(0);
	
	if (phoneNumber.length() != 8 && phoneNumber.length() != 11)
	{
		status = 1;
		cout << "Invalid phone number: " << phoneNumber << endl;
		cout << "Your call cannot be completed because:" << endl;
		cout << "A phone number must have 8 or 11 characters" << endl;
		cout << "Please try again." << endl;
	}

	else if(first != 1)
	{	
		status = 2;
		cout << "Your call cannot be completed because:" << endl;
		cout << "A phone number must begin with a 1" << endl;
		cout << "Please try again." << endl;
	}

	else status = 0;
	
	
	return status;
}

So right now it will check and see if the number is 8 or 11 digits long as well as make sure the first digit is a 1.

What I want to do now is check that each number in the phoneNumber string is a digit from 0-9, but I'm not sure how. I know how to do relational operators to check a number against a range, but I'm stumped on how to check each digit individually.

I can do it with a couple of ops and no conditional but I don't think you can get away from using a loop like a for loop to check each character.
 

Minamu

Member
Anyone familiar with using fonts in C# and XNA? If you look at the text on screen in a silly game jam game I made recently, here:

You'll see that most of the text is distorted somehow, for some strange reason. We haven't done any text manipulation as far as I know, it's a regular font file created by Visual Studio, Arial size 14. Changing resolution from the native 800*480 to 1280*720 to 1920*1080 has no apparent effect. The issue remains when toggling between windowed and fullscreen. Changing the font size however, fixes most of the issues, but in some cases, the same letters will look great and poor at random (for instance, the H in Hearts looked great at size 18 but the H in Health on the line below it looked terrible at the same time, with the same size).
 

Exuro

Member
So I'm using argouml for an assignment. I just need to make three classes, of which two are derived from one. The base class is mostly abstract, so other than a run function the derived classes share the same functions as the base. I've got everything set up except I'm not sure how to make the functions in the derived classes not be virtual. That seems to be the default and I've googled around and haven't found a solution.

Here's what I have. http://i6.minus.com/jHr0rnklOvl4C.PNG

EDIT: I should note this is just a basic template method design. I understand the processes, I'm just not familiar with uml.
 

usea

Member
Anyone familiar with using fonts in C# and XNA? If you look at the text on screen in a silly game jam game I made recently, here:

You'll see that most of the text is distorted somehow, for some strange reason. We haven't done any text manipulation as far as I know, it's a regular font file created by Visual Studio, Arial size 14. Changing resolution from the native 800*480 to 1280*720 to 1920*1080 has no apparent effect. The issue remains when toggling between windowed and fullscreen. Changing the font size however, fixes most of the issues, but in some cases, the same letters will look great and poor at random (for instance, the H in Hearts looked great at size 18 but the H in Health on the line below it looked terrible at the same time, with the same size).
How are you drawing it? Are you maybe rotating it slightly? I've only done really basic text drawing in xna (the kind you see in the introduction tutorials or on the wiki), but it never looked like that.
 

Minamu

Member
How are you drawing it? Are you maybe rotating it slightly? I've only done really basic text drawing in xna (the kind you see in the introduction tutorials or on the wiki), but it never looked like that.
My programmer is offline at the moment but from what I can see in the code, all we ever do is essentially:
Code:
State_Game.textManager.writeText("Expectation is the root of all heartache.",
				new Vector2(BaseObject.Viewport.Width / 2, 20), Color.White);

and manipulating the text so it's centered on screen. I can't see any scaling being done either. Unless this might be the culprit:
Code:
public TextInfo writeText(string text, Vector2 position, Color color)
        {
            Vector2 fontSize = font.MeasureString(text);
            position.X -= fontSize.X / 2;
            mTextInfo.Add(new TextInfo(text, position, color));
//code that deletes text from a list omitted
        }

I don't think we do any rotating, not from what I can see when I search for "text" or "font" at least.

Edit: Removing position.X -= fontSize.X / 2; seems to fix the graphical issue but screws up text placement. If I understand the code correctly, halving fontSize.X makes the middle of the string centered on screen instead of the very first char. When I write X / 1 or X / 3, the text looks nice but is placed wrong. It's currently working with X / 1.99f instead xD I love designer patching.
 

harSon

Banned
I need to learn some C#. I am using VB and ASPX for a current project at work but I want to move on to C# for other stuff. Any good books for C#?

I'm completely new to programming and I've been bouncing between these sources:

http://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners
http://www.freewebs.com/campelmxna/tutorials.htm
http://www.csharpcourse.com/

It has worked well enough for me, although I'm sure you'll breeze through them at a brisker pace since you already have a basis in programming already.
 

caffeware

Banned
Ok, I got more of my program from earlier to work!

What I want to do now is check that each number in the phoneNumber string is a digit from 0-9, but I'm not sure how. I know how to do relational operators to check a number against a range, but I'm stumped on how to check each digit individually.

Well, you could use the "isdigit()" function.

Code:
int isValid(string phoneNumber)
{
	int status = 0;
	
	if (phoneNumber.length() != 8 && phoneNumber.length() != 11)
	{
		status = 1;
		cout << "Invalid phone number: " << phoneNumber << endl;
		cout << "Your call cannot be completed because:" << endl;
		cout << "A phone number must have 8 or 11 characters" << endl;
		cout << "Please try again." << endl;
	}
	else if(phoneNumber[0] != '1')
	{	
		status = 2;
		cout << "Your call cannot be completed because:" << endl;
		cout << "A phone number must begin with a 1" << endl;
		cout << "Please try again." << endl;
	}
        else
        {
            for (size_t i = 0; i < phoneNumber.length(); ++i)
           {
              if (isdigit(phoneNumber[i]) == false)
              {
                 status = 3;
                 cout << "Not a numeric value!" << endl;
                 break;
               }
          }
        }
	
        return status;
}

By the way:

Code:
else if(first != 1) //it's a bug
else if(first != '1')//Right way: compare to char not to int
 
What do the professional SW engineers or programmers here think of certifications like Oracle's Professional Java Programmer and stuff like that? Useful, or just money-grabbing stuff?

Do employers really want this?
 
What do the professional SW engineers or programmers here think of certifications like Oracle's Professional Java Programmer and stuff like that? Useful, or just money-grabbing stuff?

Do employers really want this?

Yes they do.

Some jobs a company will like to do, especially for government work and the like, will require employees with such qualifications. It also puts you firmly above the huge pack of "I'm working towards getting certified" people who never actually do it.

I would always recommend getting at least some base level certification.
 
What do the professional SW engineers or programmers here think of certifications like Oracle's Professional Java Programmer and stuff like that? Useful, or just money-grabbing stuff?

Do employers really want this?

The importance placed upon those certifications compared to the actual skillset you walk away with is pretty vast in some cases.

Highly regarded by HR departments regardless.
 

Mabef

Banned
Ok this is a good one actually, what's going on is that the array is being created on the Stack, which is memory local to the function. Memory is set aside, populated with data, and then you're getting the address of a section of that memory and returning it to main.

Because it's the stack though, that data is not kept and now you have a pointer to memory that could have anything it. So what you want to do is create that array on the Heap, where it exists until the program ends or you explicitly free it.

In c++ the code
Code:
new int[size];
allocates a memory chunk of size (sizeof(integer) * size) on the heap and returns a pointer to the start of that memory. You can happily pass this back to main without worrying about corruption (or "function returns pointer to local variable" warnings, depending on your compiler)
Thank you! I was able to finish the program by using 'new' to send back my pointers. Here's what the final function looked like:
Code:
int *createArray(int &size)
{
    int* array = new int [size];
    
    srand ((unsigned) time(NULL));
    
    for (int i = 0; i < size; i++)
        array[i] = rand()%100;
    
    return &array[0];
}
 
What do the professional SW engineers or programmers here think of certifications like Oracle's Professional Java Programmer and stuff like that? Useful, or just money-grabbing stuff?

Do employers really want this?

There's a school of thought that says that certificates simply prove you know how to pay enough money to sit through enough seminars or tests to earn a piece of paper.

For the people that can't actually discern between candidates with skills and the candidates without, I'm sure it will be a nice tiebreaker when two candidates have otherwise the same technology vomit on their resumes and the same requisite number of years of experience that non-technical hiring people desire to see.
 

Mangotron

Member

Thanks so much for taking the time to write that out! I wanted to use isdigit from the start, but our professor will only let us use stuff he's talked about so I ended up using a find_first_not_of with 0-9. All my error codes are working now, for some reason I still can't get the formatting to work though.

Code:
string formatNumber(string phoneNumber)
{
	string formattedNumber;

	if(phoneNumber.length() == '8')
	{
		phoneNumber.insert(1, "-");
		phoneNumber.insert(5, "-");
			
	}	
	else if(phoneNumber.length() == '11')
	{
		phoneNumber.insert(1, "-");
		phoneNumber.insert(2, "(");
		phoneNumber.insert(6, ")");
		phoneNumber.insert(7, "-");
		phoneNumber.insert(11, "-");
	}	
	formattedNumber = phoneNumber;
	return formattedNumber;

}

Would the way I have this set up even work? I can't find a really clear explanation of how the .insert command functions, so I'm not sure if those lists of inserts is the right way to handle it. I know the function itself is working because it passes the number back to main() and down to the output, it just doesn't have the dashes and parentheses.
 

fenners

Member
Thank you! I was able to finish the program by using 'new' to send back my pointers. Here's what the final function looked like:
Code:
int *createArray(int &size)
{
    int* array = new int [size];
    
    srand ((unsigned) time(NULL));
    
    for (int i = 0; i < size; i++)
        array[i] = rand()%100;
    
    return &array[0];
}


Lookin' better. You don't need to pass in size by reference, as you're not changing it. And you should be able to just return array as the return type is "int *" which is what array is. &array[0] ends up being the same thing but it's more readable as array.
 
For the people that can't actually discern between candidates with skills and the candidates without, I'm sure it will be a nice tiebreaker when two candidates have otherwise the same technology vomit on their resumes and the same requisite number of years of experience that non-technical hiring people desire to see.

It isn't as simple as that, because on the other side, those certificates can be important for winning jobs and tenders.

Also even when you have a job, one of those most common things you will hear in a performance review after somebody asks for more money is that they are going to get all sorts of certifications that will help the company. It is very rare that anybody actually bothers to do it.

The people that do so? They are normally worth keeping, even if they actually learn nothing in the process.
 
Just going to have to disagree that it is an indicator of any real competence. Obviously, I know that some organizations want to see it. What I'm saying is that if I see it, I'm not moved by it.

I've seen enough resumes and talked to enough candidates with certifications and years of experience and technology vomit out the wazoo, and not many of them could talk sensibly about code. Their words betrayed them. Their coding exercises testified against them. And for those that managed to slip through the cracks, their actual code was by and large terrible.

But don't mind me. It's just that my involvement in the hiring process over the past year or so has really opened my eyes to just how bad candidates can be, and just how meaningless a lot of resume fluff actually is.
 
I don't know if I've told this interview story before, but whatever, here it goes again. There was this one dude we were interviewing. He had like 20 years experience on his resume. Went from C++ to Java to .NET. Had on his resume that he had taught Java courses at a community college, in addition to some other courses he taught.

So I'm like, as a simple icebreaker to wade into things, I'm going to toss out a softball Java question. I preface it "I see you have extensive Java experience and I..."

At this point, he cuts me off.

"I don't know Java."

I mean, at least he told me. But then, why is it listed prominently on his resume? Multiple jobs, the community college teaching experience?

Suffice it to say, he didn't get the job. Even forgetting this, he fell on his face on many, many other items in the interview. 20 years experience. Such a worthless metric.

Here's the sad thing. I do acknowledge that management has a completely different mindset. They're impressed by such things. Oh yes, they are. But they also think programmers are basically commodities. You can find a good programmer straight off the street. Just hit all the bulletpoints on the standard requirements list and that's good enough. Certifications? Wow, join now!
 
What sort of questions does your company ask Randolph? Just for reference.

Easy ones.

I work for a big bank, we're not a software house. As such, and at least on the team I'm on, 1) we don't have a lot of time to screen candidates, 2) management already thinks we're way too selective (see previous post, they just want us to recommend anybody). So we basically have 30 minutes to do a phone screen and if that goes well (usually doesn't), we'll do about an hour or so on a face-to-face.

Given the time constraints, we test your basic (and I do mean basic) knowledge of the language and tools you'll be using and then do some simple (and I do mean simple) coding exercises that nevertheless seem to exclude just about everybody. The questions are practical, given the problem domain of working on banking applications. We're not giving you a quiz to see how much of your computer science coursework you actually remember, should you have gone through that particular track (and I didn't). We're trying to see that given your 5 or more years of actual work experience, can you demonstrate that you know anything. Most people can't.
 
Just going to have to disagree that it is an indicator of any real competence. Obviously, I know that some organizations want to see it. What I'm saying is that if I see it, I'm not moved by it.

I agree that it is not an indicator of competence in any way and I would never use it as such.

When I say they may help you win a job, I'm not talking about an employee getting hired. I'm talking about winning a job for a company. When tendering for many large contracts, you will have to list the staff who are going to be working on the project, and their exact qualifications including programming certifications. Like it or not, they will then give you marks towards qualifying for whatever bullshit standard the tenderer requires or maintaining the quality system your company is itself certified for.

So this is why they can be really valuable and hence why they can really matter for the hiring or evaluation of employees. Similarly in IT a Cisco networking certification can be crucial. Does it mean you know anything? Nope. But there are a lot of sites who will not let you put a foot through the door unless you have one. If you lose your Cisco certified employees and no longer have anybody who can go to site? Well you lose the client/contract.

I agree in a business like a bank doing software development, where you will be unlikely to have such considerations it is next to useless as a way of measuring somebody (but of course will never hurt).
 
I agree that it is not an indicator of competence in any way and I would never use it as such.

When I say they may help you win a job, I'm not talking about an employee getting hired. I'm talking about winning a job for a company. When tendering for many large contracts, you will have to list the staff who are going to be working on the project, and their exact qualifications including programming certifications. Like it or not, they will then give you marks towards qualifying for whatever bullshit standard the tenderer requires.

So this is why they can be really valuable and hence why they matter for hiring or evaluating employees. Similarly in IT a Cisco networking certification can be crucial. Does it mean you know anything? Nope. But there are a lot of sites who will not let you put a foot through the door unless you have one.

I agree in a business like a bank doing software development, where you will be unlikely to have such considerations it is next to useless as a way of measuring somebody (but of course will never hurt).

Well, sure, I can agree to that, because that's just how management is. They're impressed by such shiny things. And I know why. Despite knowing better, I am impressed by such shiny things.

Take your bit about the Cisco certification. It reminded me of a friend of mine who went for his MCSE years and years ago. And I thought that if I'm hiring somebody to work on servers and desktops and builds and things such as that (things I know nothing about), I'm going to hire that guy. I justified it to myself in that brief moment by saying, "well, it's different than programming, I'm sure those certifications mean something." And then I had to slap myself, it's only different than programming because I know nothing about it. It doesn't mean that the certification means anything, it means I'm not knowledgable enough to know any better. Sounds a lot like management in many organizations.
 

Kalnos

Banned
Thanks Randolph. When I was involved in an interview process we asked the candidates a bunch of very basic programming questions and probably 9/10 were unable to correctly solve them, so I have definitely seen something similar.
 

caffeware

Banned
Would the way I have this set up even work? I can't find a really clear explanation of how the .insert command functions, so I'm not sure if those lists of inserts is the right way to handle it. I know the function itself is working because it passes the number back to main() and down to the output, it just doesn't have the dashes and parentheses.

Code:
if(phoneNumber.length() == '8')  //error!
else if(phoneNumber.length() == '11') //error!

A string is basically an array of characters. So when one compares the contents of a string one generally have to compare to a character (or to another string). Otherwise, compare numeric values with numeric values.

Code:
//each "member" of the str string is a character
string str = "gaf"; //['g']['a']['f']

The ".lenght()" function returns a numeric type, yet your comparing it to a character!

In the previous post you where comparing a character to a numeric type, now you are comparing a numeric type to a char (other way around). Compare likewise data types.

Code:
if(phoneNumber.length() == 8)  //right way
else if(phoneNumber.length() == 11) //right way

Code:
string formatNumber(string phoneNumber)
{

	if(phoneNumber.length() == 8)
	{
		phoneNumber.insert(1, "-");
		phoneNumber.insert(5, "-");

	}
	else if(phoneNumber.length() == 11)
	{
		phoneNumber.insert(1, "-");
		phoneNumber.insert(2, "(");
		phoneNumber.insert(6, ")");
		phoneNumber.insert(7, "-");
		phoneNumber.insert(11, "-");
	}

	return phoneNumber;
}

Also, you don't need the "formattedNumber" string since you passed "phoneNumber" by value. When one passes to a function by value a copy of the original string is made, so the changes made to the function's "phoneNumber" string only affect the copy made inside the function.
 
Code:
public TextInfo writeText(string text, Vector2 position, Color color)
        {
            Vector2 fontSize = font.MeasureString(text);
            position.X -= fontSize.X / 2;
            mTextInfo.Add(new TextInfo(text, position, color));

I don't think we do any rotating, not from what I can see when I search for "text" or "font" at least.

Edit: Removing position.X -= fontSize.X / 2; seems to fix the graphical issue but screws up text placement. If I understand the code correctly, halving fontSize.X makes the middle of the string centered on screen instead of the very first char. When I write X / 1 or X / 3, the text looks nice but is placed wrong. It's currently working with X / 1.99f instead xD I love designer patching.

If you are positioning with floats or you are scaling the screen, you MUST make sure the fonts are aligned 1:1 with the screen's pixel grid.

In your case, what if the screen was 1280x720 and your text 103x20? Your text will be centered at (1280/2)-(103/2) which is 640-51.5 which is 588.5, misaligned from the grid.

The solution is to cast the final x and y coordinates to int.

I doubt you are resizing your screen (e.g. drawing a game targeted for 1920x1080 on a 1280x720 screen by scaling) but that would involve a little more math. You'd have to multiply by the scaling factor, cast to int, then float divide back.
 

Minamu

Member
Thanks. Adding (int) before fontSize seems to do the trick.

Edit: No we don't do any downscaling. The default screen size is 1280*720 and when we toggle to fullscreen, we just change the PreferredBackBuffer to graphics.GraphicsDevice.DisplayMode.Width and so on.
 
Can someone help me with this:
I'm trying to put the same list of numbers into two separate arrays. The second array to be the reverse of the first. The first one initializes okay, but the second one does not. I assume it's got something to do with using marks.clear(); wrong and thus the file not returning to the start.

You only really need one loop there. When you put the values into the first array in your for loop, simply put the number in the second array at the same time but at MAX - i position.
 

Mangotron

Member

Thanks so much! Really helped me understand what I was doing much better.

The thing I don't understand now is that when I run to cursor, it shows the phoneNumber as the same value while formatNumber holds the formatted number, despite the fact that it says "return phoneNumber" at the end.
 
I have a weird math and semi-programming related question.

When dealing with integers, it's generally easy to, for example, say "2, 4, 8, 16, 32, 64, 128, 256, 512..." etc. There's a huge range of numbers from 0 to infinity.

However, when dealing with APIs that require floats between 0 and 1, for the first time, I truly realized that there is an entirely different world in between 0 and 1, all of which are reciprocals of some integer. I'm not used to dealing with them... I can say "0.5, 0.25, 0.125, 0.0625..." and then I can't go farther at all.

How do I go about mastering the world between 0 and 1? It's easy for me to say, "I need the color 121, 39, 190, 255" but then it's really hard to be so precise when dealing with floats from 0 to 1.

Or does everyone just take the lazy way and do 121/255f, 39/255f, 190/255f, 255/255f?
 

Tristam

Member
I have a weird math and semi-programming related question.

When dealing with integers, it's generally easy to, for example, say "2, 4, 8, 16, 32, 64, 128, 256, 512..." etc. There's a huge range of numbers from 0 to infinity.

However, when dealing with APIs that require floats between 0 and 1, for the first time, I truly realized that there is an entirely different world in between 0 and 1, all of which are reciprocals of some integer. I'm not used to dealing with them... I can say "0.5, 0.25, 0.125, 0.0625..." and then I can't go farther at all.

How do I go about mastering the world between 0 and 1? It's easy for me to say, "I need the color 121, 39, 190, 255" but then it's really hard to be so precise when dealing with floats from 0 to 1.

Or does everyone just take the lazy way and do 121/255f, 39/255f, 190/255f, 255/255f?

I am by no means a math or programming expert, but can't you just define some list with the desired parameter (e.g., i % 2 == 0) and then run a loop over the list values to calculate their reciprocal (and specify some desired range)?

EDIT: Don't know if I'm explaining myself well, but here's a very crude example in Python:
Code:
my_list = []
x = 1
for x in range(1, 100):
     if x % 2 == 0:
          my_list.append(x)
     x + 1
floats = [float(x) for x in my_list]
for i in floats:
     print "The reciprocal of", i, "is", 1 / i
 
Top Bottom