Eat. Sleep. Code: The Computer Programming Thread, Ver. 010

Its a bit specific, but in your case, when 9.4 goes to 9 and 73oiasfk goes to 73, the remaining characters should be left in the stream. So for instance, if you look inside the myStream varaible, you should be able to recognize that there are still characters left inside of it, and error out accordingly. Something like this



#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main() {
 int input_var = 0;
 string num ="";
 
 do {
 cout << "Enter an integer (-1 = quit): ";
 getline(cin, num);

 stringstream myStream(num);
myStream >> input_var;

 if (myStream.str().size() > 0) {
 cout << "You entered a non-integer. Exiting..." << endl;
 break;

 }
 if (input_var != -1) {
 cout << "You entered " << input_var << endl;
 }
 } while (input_var != -1);
 cout << "All done." << endl;
 system("PAUSE");
}


Unfortunately this is completely a guess as Iā€™ve not really used stringstream before, but in theory this should work. You can also just loop manually through the string, checking each digit. Outside of a ā€œ-ā€ in the first position, anything other than 0-9 is an invalid integer and you can act accordingly. Something like this:



bool isInt(string text){

for(int i = 0; i < text.size(); i++)
{
   if(text* < '0' || text* > '9') {
       //non numeric. Test for negative sign in first position
       if(i != 0 && text* != '-' )
          return false;
    }

return true;
}


This is surprisingly awkward to do in C++ :neutral_face:

Otherwise you can use strtol() like people have been doing for the last million years. Which feels very C instead of C++ but hey, itā€™s valid.



string input; // get this from wherever
char *inputPtr = input.c_str();
char *lastChar;
long int intValue = strtol(inputPtr, &lastChar, 0);
// There are other ways to check this, but this should be fine
if (*lastChar != '\0')
{
    cout << "Your entry \"" << input << "\" is not a valid integer
";
}
else
{
    cout << "You entered the number " << intValue << "
";
}


(Using stoi() is similar but without pointers being involved.)

Got an interview on Friday for a C++ dev gig. Really want it, I hate my current job.

Thanks for all of your replies. After some reading, I actually figured out a few different ways of doing it. It just seemed like a much more involved process than I thought itā€™d be.

Sorry to turn this into ā€œjob advice for axemanā€ yet again, but Iā€™m in a bit of a fork situation here:
After a year of searching for a job, I got a part-time web developer position at a small 7-person company in my city. I like the company and my co-workers, but I may lose the job in less than a year. There are two possible reasons why:

1.) I was hired to help with specific projects. Once those projects are done with, I might be gone. While the boss has said he would try to bring in more projects to keep me on, neither of us know what the future holds. This company doesnā€™t seem to have much work aside from a few key clients. I know for sure that Iā€™ll be on my particular projects until at least the end of this year, though.

2.) I may jump ship on my own because the pay overall is low. I make $19 an hour at part-time hours. So, thatā€™s about 30K a year pre-tax. The best ā€œraiseā€ Iā€™m looking at in this place in the near future is to go full-time. Thatā€™ll bump me to around 38K. While thatā€™s better than the 0 I was getting for this past year, I know this salary is low and canā€™t support me long term if something major were to happen to me.

The reason I bring this up is my job history. It took 7 months after graduating college 3 years ago to find a job. While I was at that job for a year and a half, I was laid off, and spent another year finding a job. At the moment, those unemployment gaps combined are just as big as my time actually working. If I were to lose this current job in under a year through either 1 or 2 above, I feel it will look like Iā€™m unstable on my resume. How do I combat this (assuming Iā€™m right)?

All the web developers I know are making 65k-250k a year. Sounds like youā€™re getting scammed.

Which skills do you have? If you know your stuff you should really be looking for work elsewhere.

I think a big part of it is where you live. Having an hourly rate as a developer is kinda weird anyway.

Youā€™re right. I was replying with NYC/tri-state area in mind.

If people are willing to do web development for only 30k a year, maybe I should hire someone to take care of some things to free up some time.

30k for a web developer is low anywhere I think, but it really depends what web developer means. Creating static html, something middle ground like php, or more web server java/webservice stuff as APIs for apps

I live in Flint, MI. Ainā€™t shit around here unless youā€™re already experienced. Part of the reason it took so long to find a job is that I lacked the money to move somewhere else and kept my search to places within an hour of Flint. I know the money is peanuts, but I really needed a job at the time and feel the experience could be good for me down the road.

Youā€™re right Pimp; the projects Iā€™m on right now arenā€™t intensive. Just some ASP.Net/Javascript stuff. But I hope to learn from them and branch off into more complex stuff. Iā€™m really just starting out as a web developer. My main strengths (which still werenā€™t super strong) before this job were in C# (desktop). However, I knew enough Javascript and HTML stuff (through self-study) that the boss felt I was able to tackle some things when I applied.

Thereā€™s still that resume thing though. How do I handle having huge gaps on my resume AND my most recent job lasting less than a year (assuming that happens)? Maybe it was in my head, but I think being unemployed for more than 6 months was sending a lot of red flags through employersā€™ heads. I was applying a lot, but didnā€™t get much of any interviews. I donā€™t want to be in that purgatory again, but donā€™t know how to avoid it if this job falls through. Iā€™ll still be too broke to move without risking my nest egg. The thing is, I donā€™t want to start applying for other work and maybe get an offer before these projects are done. But after theyā€™re done, who knows? If I smell a canning about to happen, Iā€™ll try to jump ship before Iā€™m laid off again. But how will I know it before it happens?

A lot of web developer stuff can be done remotely, I have no idea what the local job market is like but I canā€™t imagine its that good for tech in michigan. In my area, cali, I am probably contacted by headhunters once a week. Maybe you can find something remote?

See, now i may sound like a jerk for saying this, but certain languages are easier to write and understand while producing the same outcome. I mean, why use C++ if you can use C#? Why use C# if you can use VB. I like VB. You donā€™t have to worry about silly ā€œcurly bracesā€ and stuff like that. I donā€™t understand why people say ā€œlazy programmersā€ or ā€œyou are not a programmerā€ if you donā€™t use language x or language y. For example, in my experience, using stored procedure and writing the bulk of your code with Transact-SQL is more effecient than using views or using other languages to write the bulk within an MS SQL databaseā€¦

This is utterly random, but I thought of something: why donā€™t we talk about the absolute lowest or stupidest job offers we got? Just for fun. While I was running through my head about my current job, I reminded myself about an abysmal offer I had February of this year (6 months after my layoff).

It was special in all that preceded it: I applied for a job at a insurance software company, and after a phone interview the head IT guy decided I didnā€™t have what they were looking for. However, I talked about getting stuff up on GitHub to make myself more marketable, and he suggested to me a project I could do to put up: Invaders (the video game). There was a lab in the Head First seriesā€™ C# book for building the game. They donā€™t do everything for you; you have to piece it together from previous book knowledge and hints here and there. If I was able to get that (and more things of that depth) up there, that might be at least something to talk about in interviews. I DLed the book and went through it up until I had that game done. That game is now one of two big projects on my GitHub (I know; I need more).

I called the guy back saying I completed it. I was hoping for just critiques, but he set up a phone/GoToMeeting interview. They saw the game from my screen, and decided to bring me in for a real interview. At that interview, the head IT guy and a potential co-worker of mine had a long conversation about how Iā€™d have to move closer if I didnā€™t want the commute to wear me down in a few months. I forgot to mention: the company was in Troy, MI, which was an hour away from Flint in distance and apparently light years away in standard of living. This will be important very soon. After the convo, they tested me by having me change some things about the game (forgot what they were) to gauge how I designed things. I passed the test, because they started talking about how things are for the company in learning curve. It would take me 6 to 9 months to get up to speed with their systems. They had huge programs. After that convo, they said theyā€™d be happy to put me onā€¦ for $22,000 to start.
ā€¦
ā€¦
We had just spoken for about 15 minutes about how Iā€™d have to move to Troy, which was more expensive than Flint. Until I found an apartment, Iā€™d have to bear the commute, which would quadruple my gas costs. Thereā€™s a 6 month learning curve to the companyā€™s stuff, meaning I probably wonā€™t get any type of raise for at least that time. But they wanted to start me out at 22K. The head guy suggested I take a week to think on it, but I think we both knew I wasnā€™t taking it by my facial reaction. I was like Thor in the Ultron trailer when Cap got the hammer to move just a bit. Maybe not that obvious, but it was clear any happiness I had up until that point was dead. We said peaceful goodbyes and I let them know Iā€™d be passing a week later.

Iā€™m happy I did the C# project and the GitHub stuff; Iā€™d probably still have a blank GitHub without the suggestion. Thatā€™s the reason I can laugh about the offer instead of being enraged. Still, how do you do that? How do you offer such a piss-poor salary to a new hire who you KNOW will get killed on bills just trying to get to work? In retrospect, I think they legitimately didnā€™t have the money to be starting out new hires at 40-60K. STILL, how does that not come up at some point before all the stuff I just mentioned? Did they think disclosing the salary would make them look unattractive? As compared to disclosing the salary after blowing away an hour of peopleā€™s time? Ugh.

I would have said, ā€œIā€™ll let you know regarding the postion.ā€ Or something to that effect. In other words, say something to them that they would say to you when you full well know that they will not call you back.

I WOULD have done something like that, but I was so caught off-guard by the low salary. That was less than I was making at my previous job (which was only 10 minutes away). I wasnā€™t able to find this companyā€™s salaries at the time on a website like Glassdoor, and got hit with that.

Anytime youā€™re being offered unskilled wages for something like this its hilarious. I took my first job offer outta school, asked for 50k. 6 years later I am making 6 figures now and its only gonna go up.

As for languages, it depends what youā€™re doing it for. When you need to optimize something in C# vs C++ youā€™re gonna wish you had that higher level of control.

I know, and thatā€™s been the absolute most painful thing about this whole job hunt and the prospects of my future. I know the good salaries are out there. Iā€™ve interviewed for companies that had them (more interested in the company, of course, but still). Yet, the only ones that seem to want to put me on are the little fly-by-night operations that can can say 22K to start with a straight face. I already have an inferiority complex, so this shit is starting to fuck with my morale. It hurts to only hear back from these rinky-dink places when you know for a fact that just 40-50K (after taxes) would wipe out your student loan debt in a year and let you move into an apartment with no roommate. This field is filled with competition though.

Looks like Iā€™m in the same boat. I make gross roughly $40,000 but have a CS degree and their excuses for not hiring me is the ā€œlack of experienceā€. Gimme a break LOL

Its joke times

Your mother is so fat it would require 2 large integer variables to store her weight, else she would cause a buffer overflow.

update on the game Iā€™m working on, you might be able to tell what itā€™s based on. You can probably tell there are a few issues, like blocks destroying the wrong blocks, and the button input is really sensitive.

Itā€™s been a bit of a headache trying to fix null pointer errors and index out of bounds, oh jeez and the collision detection. There were times when block would just teleport into new positions and the game crawl to 2 frames per second.