r/programminghelp • • Aug 01 '20

JavaScript ELI5: The is-number package in JavaScript

4 Upvotes

Anyone mind explaining the implementation? I have no idea why it works at all.

Here's the code: https://www.github.com/jonschlinkert/is-number/tree/master/index.js


r/programminghelp • • Jul 29 '20

JavaScript How can I make a list of repsonses in a JavaScript chat bot?

4 Upvotes

I have Googled for weeks and weeks and weeks and I just CAN'T find an answer that's understandable.

I'm new to JavaScript so I'm making a very simple chat bot. "Hello, how are you", that kind of thing.

I can't find a way to store all the possible messages that the user could send, and the possible responses, so they can be called on. Here's what I mean:

If I type "Hello", it should respond with "Hello, how are you?". So far, the only way I can find that works is to create a ridiculously long if/else statement with every possible message I could send, as a possibility in that statement. For example

if...hello etc

else if... hi

else if... what's up

else if... what's the weather

There MUST be a better way of storing strings and calling them based on user input but I can't find the solution. Could someone please help a newbie?

Thanks in advance :)


r/programminghelp • • Jul 29 '20

Java simple code need help (Java)

4 Upvotes

in this code, If I put in 12 I am supposed to get 12.72, but get 12.00.72

any advice, not sure how to change that

import java.util.Scanner;
public class DebugTwo4
{
public static void main(String[] args)
   {
Scanner input = new Scanner(System.in);
String costString;
double cost;
final double TAX = 0.06;
      System.out.println("Enter price of item you are buying");
      costString = input.next();
      cost = Double.parseDouble(costString);
      System.out.println("With " + TAX * 100 +
"% tax,  purchase  is $" + cost + cost * TAX);
   }    
}


r/programminghelp • • Jul 25 '20

Python Solution breakdown help - High Five problem (Python)

4 Upvotes

This is the High Five problem (Leetcode). I found the working solution pasted below (Python) and I don't understand it. I have a working knowledge of Python, but I'm thrown off by the different data structures. I made substitutions for the loops but the results did not convey anything of substance to me. I'm especially confused by items: List[List[int]]) -> List[List[int]

Can anyone break down the solution for me?

Problem:

Given a list of scores of different students, return the average score of each student's top five scores in the order of each student's id.
Each entry items[i]has items[i][0]the student's id, and items[i][1]the student's score.  The average score is calculated using integer division.
Example 1:
Input: [[1,91],[1,92],[2,93],[2,97],[1,60],[2,77],[1,65],[1,87],[1,100],[2,100],[2,76]]
Output: [[1,87],[2,88]]
Explanation: The average of the student with id = 1 is 87. The average of the student with id = 2 is 88.6. But with integer division their average converts to 88.
Note:
1 <= items.length <= 1000
items[i].length == 2
The IDs of the students is between 1 to 1000
The score of the students is between 1 to 100
For each student, there are at least 5 scores

Solution:

class Solution:
    def highFive(self, items: List[List[int]]) -> List[List[int]]:
        items.sort(reverse=True)
        
        res = []
        curr = []
        idx = items[0][0]
        
        for i, val in items:
            if i == idx:
                if len(curr) < 5:
                    curr.append(val)
            else:
                res.append([idx, sum(curr) // len(curr)])
                curr = [val]
                idx = i
        
        res.append([idx, sum(curr) // len(curr)])
        
        res = res[::-1]
        
        return res

r/programminghelp • • Jul 16 '20

Other RasPi Dashcam Project

4 Upvotes

So I have very limited programming experience but would love to learn more about it through a project I've wanted to take on for my car. So, the long and short of it is if anyone knows of any projects similar to this and could point me in the direction of githubs or repositories that I could modify it would be great. So, what I want to do is an integrated two part safety/dashcam system. I'm wanting to use a RasPi, and the premise behind the project is this: Raspi can have a usb or storage device plugged into it, that while the car is running, footage from a rear camera and a front dashcam can be saved on it in 5 minute sections until the storage is full in which case it overwrites the oldest files. Simple so far and I've found a couple of codes that can do that. However I would also like to hook the RasPi up to a mini display that I'll have on my dash that will have a toggle switch to select which camera is being displayed on the screen (my car has very little in the way of rear vision, so I would like to be able to have a monitor showing the reversing cam just so i can see that blind spot). Anyways I know its a bit of an ask and if there is a more relevant sub to post this to let me know!


r/programminghelp • • Jul 14 '20

Java A question about Java

4 Upvotes

So in java you can make calculations like 3+1 now my question is if i ask for input lets say in a calculator and the second string is + (the first one would be 3 and the third one would be 1) how can i convert the + from a string into a symbol that i can make calculations with


r/programminghelp • • Jul 10 '20

Processing Program My Own Debit Terminal?

4 Upvotes

Would there be a way for me to purchase a debit terminal for my small business and code my own debit terminal to use for customers so that I don't need to use third party company and I can save a ton on fees?


r/programminghelp • • Jul 09 '20

Answered C: invalid operands

4 Upvotes

New to C and programming in general, making a compound interest calculator.

getting a compiler error:
$ gcc main.c

main.c: In function ‘main’: main.c:19:62: error: invalid operands to binary ^ (have ‘double’ and ‘int’ amount = (principal * (1.0+(interestRate / compoudPerYear)) ^ (compoudPerYear * time)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~)

source code: https://pastebin.com/HtaC1Tqx

it does not like me doing math operations on a double and int together, but i need a double type for the equation to work.


r/programminghelp • • Jul 04 '20

Other What is the best language(s)/framework for this project?

4 Upvotes

Hi there, so I run the student newspaper at my university and I also happen to be a computer science student. I’m about halfway through my program, so I’m still not super experienced, but really want to dig my teeth into some bigger projects

I’d like to possibly develop a mobile app for the paper, but I don’t know where to begin. I’ll need some sort of content management system, and ideally we could get the articles scraped from our website automatically put into the mobile app system, and we can choose what articles to where from the admin panel of the app.

How should I go about getting started for this projected? Are there any particular frameworks or languages that would be helpful (other than the languages for the actual development of the app)


r/programminghelp • • Jun 25 '20

SQL SQL lookup table advice.

4 Upvotes

I'm making a ticketing system and I have a lookup table with statuses. ex: unassigned, open, InProgress, postponed, closed, etc. I want to log every time a ticket changes status and the time it changed. A ticked can be put InProgress or Postponed or any other status multiple times. I want to log EVERY action with time codes. what is the best way of doing it? should I have a different table with the ticketID and the statusID with the timecode or id there a better way?

example:
ticket 1, Open, 6/24/2020 12:00PM
ticket 1, InProgress, 6/24/2020 1:00PM
ticket 1, Postponed, 6/24/2020 1:10PM
ticket 1, InProgress, 6/25/2020 8:00AM
ticket 1, Closed, 6/25/2020 8:30AM


r/programminghelp • • Jun 12 '20

Java User input validation help

4 Upvotes

I've been tearing my hair out about how to make this assignment work. I am provided with code that takes two doubles, wallHeight and wallWidth, and multiplies them to get wallArea. My assignment is to use do/while loops that will continue to prompt the user for input if an invalid input is entered. I had no problem sorting out how to not let people input negative numbers. We are supposed to ALSO be learning how to use try/catch blocks to deal with when users attempt to input non-numbers.

I simply can't figure out how to use the two in conjunction. This is the functional do/while block that will continue to prompt if you don't enter positive numbers.

import java.util.Scanner;
public class Paint1 {
    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        double wallHeight = 0.0;
        double wallWidth = 0.0;
        double wallArea = 0.0;
        double gallonsPaintNeeded = 0.0;     
        final double squareFeetPerGallons = 350.0;
 
        // Implement a do-while loop to ensure input is valid          
        do {
        System.out.println("Enter wall height (feet): ");
        wallHeight = scnr.nextDouble();
        } while (wallHeight <= 0);

        // Implement a do-while loop to ensure input is valid
        // Prompt user to input wall's width
        
        do {
        System.out.println("Enter wall width (feet): ");
        wallWidth = scnr.nextDouble();
        } while (wallWidth <= 0);
        
        // Calculate and output wall area
        wallArea = wallHeight * wallWidth;
        System.out.println("Wall area: " + wallArea + "square feet");

        // Calculate and output the amount of paint (in gallons) needed to paint the wall
        gallonsPaintNeeded = wallArea/squareFeetPerGallons;
        System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons");        
    }
}

My best attempt at try/catch blocks AT BEST simply stops the code because without the break statements it goes infinite, and it looks like this:

import java.util.Scanner;

public class Paint1 {

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        double wallHeight = 0.0;
        double wallWidth = 0.0;
        double wallArea = 0.0;
        double gallonsPaintNeeded = 0.0;
        
        final double squareFeetPerGallons = 350.0;
        

        // Implement a do-while loop to ensure input is valid  
        
        do {
        	try {
        		System.out.println("Enter wall height (feet): ");
        		wallHeight = scnr.nextDouble();
        		}
        	catch(Exception excpt){
        		System.out.println("Invalid input.");
        		break;
        	}
        } while (wallHeight <= 0);

        // Implement a do-while loop to ensure input is valid
        // Prompt user to input wall's width
        
        do {
        	try {
        		System.out.println("Enter wall width (feet): ");
        		wallWidth = scnr.nextDouble();
        		}
        	catch(Exception excpt) {
        		System.out.println("Invalid input.");
        		break;
        	}
        } while (wallWidth <= 0);
        
        // Calculate and output wall area
        wallArea = wallHeight * wallWidth;
        System.out.println("Wall area: " + wallArea + "square feet");

        // Calculate and output the amount of paint (in gallons) needed to paint the wall
        gallonsPaintNeeded = wallArea/squareFeetPerGallons;
        System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons");        
    }
}

I'm sure this is a mess, but I feel WOEFULLY unprepared for this. I'd appreciate any pointers in the correct direction.


r/programminghelp • • Jun 11 '20

C Compiling a graphics driver using ReactOS Build Environment

4 Upvotes

Can someone help me do that? Its source can be found at https://github.com/Zero3K/boxvnt/.


r/programminghelp • • Jun 05 '20

C++ Trying to make a checkers game in C++, but having trouble with pieces jumping over each other (see line 165)

4 Upvotes

r/programminghelp • • May 28 '20

Answered Enqueue and Dequeue error

4 Upvotes

I am trying to create a queue program with Add, Remove, Count functions. When I use enqueue or dequeue it says "Queue does not contain the definition for Enqueue/Dequeue".

https://pastebin.com/bbbFcB6Z


r/programminghelp • • May 27 '20

Answered How would one publish a website?

4 Upvotes

If this question has already been asked, I apologize.

If I had the HTML code and the domain, what else would I have to do to publish the website? I've looked elsewhere online and I can't make sense of it. I can provide clarification if necessary.


r/programminghelp • • May 02 '20

Python I need help with this If statement

4 Upvotes

I am a complete beginner in python and I am doing some code practicing from the website codingbat.com Anyways, I have reached this question and I need help with it

We have a loud talking parrot. The "hour" parameter is the current hour time in the range 0 to 23. We are in trouble if the parrot is talking and the hour is before 7 or after 20. Return True if we are in trouble.

def parrot_trouble(talking, hour):

Now my question is how to ensure that the number does not exceed above 23 and below 0 and be able to write it in a code

Even the slightest assitance helps. Thanks!


r/programminghelp • • Mar 31 '20

Python Iterating using python's datetime.date

4 Upvotes

So, I'm making a program that requires an array of each date between two given dates -

start = datetime.date(2020,1,1)
end = datetime.date(2020,12,31)
myArr = [all dates between (and including) start and end]

Is there a way to fill this array with every valid date between those two?


r/programminghelp • • Mar 12 '20

Answered Selecting random value in array

4 Upvotes

Hello

I am trying to select a random value in the array. It does it but the number is the same when i run it. How do I do it so the number is randomly selected when i run the program?

srand((int)time(NULL));

int rand_num = rand() % 4; //generates a random number between 0 and 3

int pos_values[4] = { 1,35,203,765 };


r/programminghelp • • Feb 28 '20

Python Help finding Python documentation on sys.stdin.read() or another multiline user input method

4 Upvotes

So te thing is, I want to get a multiline input from the user. After some searching i found the suggestion of using sys.stdin.read() . Which is supposed to be able to do this with the ending character being Ctrl + D. But when I try it it wont end the input. So I need help with finding the doc on the matter. And/or another solution.


r/programminghelp • • Feb 14 '20

C++ Anyone know a way to program a game in c++(moon lander) on an android tablet?

4 Upvotes

My friend only has a android tablet. We’re programming a game with a GUI and he is not sure if their is away/ application that he can use to program this game.


r/programminghelp • • Feb 05 '20

Python What is the ELI5 of __init__ and self in Python?

4 Upvotes

r/programminghelp • • Jan 07 '20

Answered Could I get some help learning how to use C# or unity?

4 Upvotes

For a high school project we have to create our own game and I'm planning on using unity but I was told that to use unity it helps to learn C# so I figured I'd ask if anyone knew any good places to start in general.


r/programminghelp • • Jan 04 '20

I’m not tech savvy, so please dumb down the answer as much as possible: What is the purpose of CX_Freeze: Python?

4 Upvotes

I turned on a PC and was greeted with that with saying main script error. Is this something I should worry about?


r/programminghelp • • Dec 27 '19

Answered Unkown conditions for strange bug. Not looking for fix, but when it occurs

4 Upvotes

I normally code in python, but I decided to branch out to p5.js. I have a background. After ~4 hours, I had the semi-working model that is on github under user vraneb, repo PowerGrid. A bug occurs under situation I can’t quite figure out. The controls are as follows:

1: create a new node at the mouse, except when hovering over another, then select or connect it.

2: create a new power station at the mouse, except when hovering over another, then select or connect it.

d: delete the selected site (node or station) if selected, otherwise select the site hovered over. This is where the bug is occurring.

Any other key: select a site hovered over, or connect to the site hovered over if there is already on selected.

GitHub

The bug is a connection remaining to a nonexistent site, and disappears when the offending site is deleted.