Remove ads, unlock a dark mode theme, and get other perks by upgrading your account. Experience the website the way it's meant to be.

Programming • Page 4

Discussion in 'Technology Forum' started by Dirty Sanchez, Mar 5, 2016.

  1. Nick

    @fangclubb Prestigious

    These are the changes I could see from reading the code.

    double *getData(string fileName, double temperature[], int &nDays)
    {
     ifstream inFile;
     inFile.open(fileName.c_str());
    
     nDays = 0;
     double dailyTemp;
    
    
     while (inFile >> dailyTemp)
     {
       cout << temperature << " and June " << nDays << endl;
       temperature[nDays] = dailyTemp;
       nDays++;
     }
     return temperature;
    }
    
    double findHighestTemp(double temperature[], int numDays)
    {
        double highest;
        for (int i = 1; i > numDays; i++)
        {
    
            if (highest < temperature)
            highest = temperature;
        }
    
        return highest;
    
    }
     
  2. @DeviantRogue A few things with findHighestTemp:

    (int i = 1; i > numDays; i++)
    This loop will never run unless numDays is 0 (which doesn't make sense), because you'll only enter into the loop if i > numDays is true, and you've just declared i = 1. You probably want to do:

    (int i = 0; i < numDays; i++)

    And then when you do int higest = i (aside from misspelling "highest"), you're setting "highest" to be the index of the temperature, not the temperature itself. For example, if "72" is the second value in the list, you're setting temperature to 1 (because indexes start at 0, so index 1 is actually the second value). You want to do

    if (highest < temperature[i]) {
      highest = temperature[i];
    }

    For both "showDaysOver100" and "averageTemp" -- you initialize variables to 0 inside the for loop. So for example if you find a day that's over 100 degrees, you'll do dayOver100++ (which will set dayOver100 to 1), and then the very next iteration, you set dayOver100 back to 0. So that value will only ever be 0 or 1. You need to initialize variables outside of loops.
     
  3. DeviantRogue

    Take arms, it'll all blow over Prestigious

    I actually did do i = 0, < numDays!


    Nick trying to lead me astray!
     
  4. Nick

    @fangclubb Prestigious

    lmao sorry! must have been my phone hahaha
     
    DeviantRogue likes this.
  5. matthaber

    beautiful and chequered, the end

    Oh seems I am too late and most of the things I would of said have been picked up on already. The main things I would of said (which scott already pointed out) is make sure to declare your variables outside of your loops or else its gonna reset it too zero on every iteration (always try and declare your variables at the start of the function).

    another thing I would keep in mind is remembering that when you declare a variable , that variable only exists within the context of that function, so in your showDaysOver100 function you have
    if (temperature[i] => tempOver100)
            {
                int dayOver100 = 0;
                dayover100++;
            }
    
    declaring the dayOver100, but then in your main() you try and call dayOver100
    cout << "Number of days over 100 : " << dayover100 << endl;
    
    which is gonna throw a syntax error, because dayOver100 has not been declared within the context of main().

    For the most part i'd say there are just a bunch of small syntax errors which 5/10 minutes debugging it would easily fix. A lot of these problems Id say come over having very similar variable names, which then became very easy to lose track of (causing you to call the wrong one at the wrong time). Example of this is you have:

    showDaysOver100
    numDaysOver100
    dayOver100
    numDays

    which are all small variations of each other, which I think is probably what caused you to accidentally type "dayover100" over "numdaysover100", and because you are using camelCase, these variables kind of all blend into one. The best tip I can give when it comes to syntax is to avoid camelCase (unless your class is specifically telling you, you have too) from my experience it makes everything a lot harder to read, and no one in the real world uses it.

    The other big syntax related problem I see is in your getData function. You are passing in the variable "temperature" which is an array holding all the temperatures, but then you go on to declare a variable called "temperature" which holds the singular temperature of a day, thus you have two variables named the same thing. You will have to change one of them.

    I'd say just keep trying to compile the code and fix the syntax problems that arise 1 by 1, shouldn't take you too long. If you are still having problems identifying them though let me know, cause I can show you what I fixed to get it compiling.
     
  6. It's personal preference I suppose, but I very much disagree. I exclusively see camelCase for variable names in the real world, and imo they're easy to read. What's the alternative? Underscores? Yuck.
     
    stnewton likes this.
  7. Nick

    @fangclubb Prestigious

    Fuck deleted instead of edited. The biggest problem I think he was having is it wasn't compiling due to the getData function so probably got stuck trying to fix that other than the small debugging fixes.

    I couldn't live without camelCase. Makes everything much easier to read for me. I'm doing Web dev at the minute and struggling to get used to dashes separating words.
     
    stnewton likes this.
  8. matthaber

    beautiful and chequered, the end

    @scott @Nick

    K i must be crazy then. Dont listen to me when it comes to syntax @DeviantRogue. Ive probably just spent too much time in python, but I will live and die by underscores. So so so much easier for me to read. I find with camelCase it just ends up blending all the words together making it so much harder for me to recognize at a quick glance what said variable/function purpose is.
     
  9. noxee Mar 30, 2016
    (Last edited: Mar 30, 2016)
    noxee

    Regular Prestigious

    @DeviantRogue I've tried to a little bit of a code review here:

    DeviantRouge code review ยท GitHub

    The review also has comments that link to my own implementations, one using arrays, and one using vectors. I would strongly suggest to get your own version working first and then if you're curious to check them out.
     
    scott likes this.
  10. Nick

    @fangclubb Prestigious

    Suppose it's just whatever you get used to but I do find camelCase very clean @matthaber

    Has there been any decent developments from Microsoft Build?
     
  11. Nick

    @fangclubb Prestigious

    @noxee was going to mention vectors myself but he mentioned his class was doing arrays so I held off. I really hate how limited arrays are
     
  12. noxee

    Regular Prestigious

    @Nick yeah vectors would be ideal but I tried to write my review so that it was applicable to using arrays as well. Most of my comments should still hold true for an array implementation.

    You could always make the very loose argument that vectors are a form of dynamically allocated array so "technically" you're using an array. But it's a bit of a stretch given the additional functionality you get with a vector.
     
    Nick likes this.
  13. matthaber

    beautiful and chequered, the end

    it was just announced bash command line is being built into the windows OS. was not expecting that at all.
     
    Dirty Sanchez likes this.
  14. DeviantRogue

    Take arms, it'll all blow over Prestigious

    Thanks for all the help guys, gonna sit down for some dinner and then hopefully get this program running properly by 10. :)
     
  15. drewinseries

    Drew

    Just started R for one of my classes, been looking forward to get into it to branch away from all the object oriented stuff my other classes have been doing. That and I am doing Assembly now as well, god help me.
     
  16. Nick

    @fangclubb Prestigious

    R is awful! Assembly is fun though. I made pong in it.
     
  17. fishguts182

    Regular

    I had to program the game Snake in assembly for my microprocessor class. Assembly was fun until that project.
     
    Nick likes this.
  18. Nick

    @fangclubb Prestigious

    Hah! Thankfully pong wasn't a project for college just a thing for fun at the end of the class.
     
    fishguts182 likes this.
  19. drewinseries

    Drew

    I have a BS in biology, and most of the bio computational world always has python and R as job requirements.
     
  20. noxee

    Regular Prestigious

    Saw this posted on HackerNews today and thought it would be quite amusing to people in this thread.

    This should never happen
    .
     
    scott likes this.
  21. So much to catch up on!
    This post pains me. Scheme/Lisp forever.

    I use different cases for different languages / different aspects of a language.

    For example, camelCase in Java/C++; snake_case for functions and variables, but CapsCase for classes in Python.

    I get all screwed up when I switch between languages though. My JS code is riddled with snake and camel.
     
    scott likes this.
  22. zigbigwig

    I Miss Jake W Prestigious

    Swift/ObjC represent.
     
    stnewton likes this.
  23. zigbigwig

    I Miss Jake W Prestigious

  24. matthaber

    beautiful and chequered, the end

    gonna rant for a second....

    it seriously sucks being the only dev-ops in a company. People just assume/rely on you being free 24/7 every day of the week incase something bad happens. Heck, today I reminded my boss that I wont be here april 15th because ill be out of the country (for BWM fest) only to learn we have a major app deployment that night (which I am the only person who can/knows how to do it). Thankfully they signed off on my vacation days already so there is absolutely no way they can tell me I have to be here. Im just now in an awkward position where I have to teach deploying the app to someone who really doesn't wanna have to do it, and I can tell they a little annoyed i wont be there.

    I like the majority of stuff I get to do as a dev-ops but god I hate being on call all the fucking time with this shit. I shouldn't feel bad for going on vacation, but ill be going to europe for 2 weeks and i know people are gonna be annoyed I wont be in the office for that time cause we have no other ops people to help cover stuff.
     
  25. Snewt

    Does whatever a spider can. Prestigious