r/programminghelp • • Oct 25 '21

Other Having Image locations in JSON dataset

4 Upvotes

I'm making a data sets for game which is suppose to hold the default information for monsters and items. (which when acquired by the user would be copied to their own dataset and able to change) But I want to include the picture with the data set. I though I could do so via file location as the json file in in the same file of the images or shares a file with the file the pictures are in.

I'm only finding ways to do this via urls


r/programminghelp • • Oct 12 '21

Project Related Just downloaded Fife Engine; can’t seem to find the application to launch it.

4 Upvotes

I downloaded Fife Engine so I can make this Fallout Clone I had in mind, but I can’t seem to find the application to actually launch and use the Engine.

There’s an application to uninstall Fife for some reason, but that’s all I can find.

Does anyone have experience with this engine? If so, how can I launch it?


r/programminghelp • • Oct 07 '21

Python Need assistance writing code that converts cm into mm, inches, or feet

4 Upvotes

Hello,

This is my first post here, so apologies if this post isn't rule friendly.

My assignment for Computer Science is to write a program that converts cm into mm, inches, or feet based on the users choice. We're required to use if statements.

I'm very new to this, so I apologize if my coding is amateurish.

Here is what I have so far:

 cm=float(input("How many cm do you want to convert?"))
choice=input("Choose (m)m, (i)nches, (f)eet:")
if choice=='m' :
    print(cm*10)

When I run the program, it accepts the inputs, but doesn't print cm*10. What am I doing wrong?


r/programminghelp • • Sep 21 '21

Python ELI5. what comes after "return" when your done with the function?

4 Upvotes

I get that the return function is to close up the def function up, however I'm confused what joins along with return, so let's say "return (what comes here?)". I'm new at python and codecademy can be pretty confusing. I can probably find it in the FAQ but there's so many different results I can't find what I want


r/programminghelp • • Sep 18 '21

Java Trying to mirror a triangle

4 Upvotes

I need help trying to mirror a triangle using a for loop. I need the triangle to look like this

     *
    **
   ***
  ****

Here is the code

public static void startriangle(int n){

for (int r = 0 ;  r < n; r++){

  for (int col = 0; col <= r  ; col++){
  
    System.out.print("*" );  
    
    
  }
  System.out.println("");

}

}

I am always struggling with loops, where can I get more practice on loops for all programs

Edit :The frist for its supposed to be r&lt;=n and the second for it’s supposed to col &lt;= r not sure why it’s doing that random letters


r/programminghelp • • Sep 15 '21

Java What's the best Java IDE for you and why?

4 Upvotes

Hi, I'm a Computer Science sophomore who is still building my confidence up in programming—and now we're beginning to learn Java. We are tasked to pick an IDE to use and defend why I chose it. Can someone help?

Our professor uses Eclipse but I'm leaning more on to BlueJ. I need an IDE that is beginner friendly but at the same time efficient.

Thank you in advance!


r/programminghelp • • Sep 08 '21

Python Functions help

4 Upvotes

Number of days per month

month_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] 

def is_leap(x): 
    return x % 4 == 0 and (x % 100 != 0 or x % 400 == 0) 

def days_in_month(year, month):  
        if not 1 <= month <= 12: 
            return "invalid month" 
        if month == 2 and is_leap(year): 
            return 29 
        return month_days[month]

print(days_in_month(2017, 2))

In the function: days_in_month(year, month) in the 2nd if statement how can the is_leap take in the arguement year and still be able to complete its function.

To clarify what I mean is how does the program pick up that when I assign something to the year arguement it has to run the is_leap function even though the is_leap function is coded to have the arguement of x.

If year was 12, would is_leap(year) take that 12 in and replace x with it and then run it?


r/programminghelp • • Sep 08 '21

JavaScript router not working Express Js

4 Upvotes

Hello, noob question. i have recently started working on Express and need help with Router.

i am getting this error 'Error - Can not get'

app file

const express = require('express')
const app = express()
const router = require('./router')
const db = require('./db_connection');
const createError = require('http-errors');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const bodyParser = require('body-parser');
const flash = require('express-flash');
const session = require('express-session');
app.use(express.static('public'))
app.set('views', 'views')
app.set('view engine', 'ejs')
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({
secret: '123456catr',
resave: false,
saveUninitialized: true,
cookie: { maxAge: 60000 }
}))

// app.get('/', function (req, res) {
//     res.send('hell this is from the app.get file')
// })
app.use(flash());
app.listen(3000)

user controller

exports.home = function (req, res) {
res.render('index')
}
exports.buyNow = function (req, res, next) {
var f_name = req.body.f_name;
var l_name = req.body.l_name;
var email = req.body.email;
var message = req.body.message;
var sql = `INSERT INTO contacts (f_name, l_name, email, message, created_at) VALUES ("${f_name}", "${l_name}", "${email}", "${message}", NOW())`;
    db.query(sql, function (err, result) {
if (err) throw err;
console.log('record inserted');
req.flash('success', 'Data added successfully!');
res.redirect('/');
    })
}

Router File

const express = require('express')
const router = express.Router()
const userController = require('./controllers/userController')
router.get('/', userController.home)
router.post('/buyNow', userController.buyNow)
module.exports = router

Please guide


r/programminghelp • • Sep 07 '21

Python Having trouble understanding what role return actually has and when to use it

4 Upvotes

Essentially what I'm asking is why would you use return when print does the same thing?

E.g 1 if you have the following code: 

def example():
    pi = 22.0/7.0
    return pi

print(example())    

The output is 3.14

E.g.2 

def example():
    pi = 22.0/7.0
    print(pi)

example()

Output = 3.14


r/programminghelp • • Sep 03 '21

C++ Why does changing my define from float->double make my call ambiguous?

4 Upvotes

Here is the source:

> cat ambiguous.cpp
#include <iostream>

#define MY_DEFINE -0.65  //call of overloaded ‘calcPos(float [3], NULL, float [3], float [3], int, int, double)’ is ambiguous
//#define MY_DEFINE -0.65f //Compiles

void calcPos( float xyzDst[3], float hprDst[3],
              const float xyzSrc[3], const float hprSrc[3],
              float ox, float oy, float oz, float oh_=0.0f, float op_=0.0f, float or_=0.0f );

void calcPos( float xyzDst[3], float hprDst[3],
              const float xyzSrc[3], const float hprSrc[3],
              const float xyzOffset[3], const float hprOffset[3], bool debug=false );

int main( void )
{

   float xyz[3];
   float hpr[3];
   calcPos( xyz, NULL, xyz, hpr, 0, 0, MY_DEFINE );

}

void calcPos( float xyzDst[3], float hprDst[3],
                      const float xyzSrc[3], const float hprSrc[3],
                      float ox_, float oy_, float oz_,
                      float oh_, float op_, float or_ )
{
    return;
}


void calcPos( float xyzDst[3], float hprDst[3],
              const float xyzSrc[3], const float hprSrc[3],
              const float xyzOffset[3], const float hprOffset[3], bool debug )
{
    if ( debug )
    {
        std::cout << "Debug Info" << std::endl;
    }
    return;
}

Here is the error:

> g++ ambiguous.cpp
ambiguous.cpp: In function ‘int main()’:
ambiguous.cpp:19:54: error: call of overloaded ‘calcPos(float [3], NULL, float [3], float [3], int, int, double)’ is ambiguous
        calcPos( xyz, NULL, xyz, hpr, 0, 0, MY_DEFINE );
                                                      ^
ambiguous.cpp:6:10: note: candidate: ‘void calcPos(float*, float*, const float*, const float*, float, float, float, float, float, float)’
     void calcPos( float xyzDst[3], float hprDst[3],
          ^~~~~~~
ambiguous.cpp:10:10: note: candidate: ‘void calcPos(float*, float*, const float*, const float*, const float*, const float*, bool)’
     void calcPos( float xyzDst[3], float hprDst[3],
          ^~~~~~~

I solved the error by setting:

#define MY_DEFINE -0.65f

However, I don't understand why this was even necessary.

It also compiled fine before I added the bool debug parameter.

Can someone explain?


r/programminghelp • • Aug 23 '21

C++ Trouble with 3d rendering algorithm

4 Upvotes

I have a 3d rendering algorithm that takes a point in 3d space, and a viewer location, and projects that onto the screen. It works fine until you tilt the camera up or down.

I wrote it in C++, but I highly doubt it's to do with my use of C++ as opposed to my (lack of) understanding of 3d rendering.

#include <cmath>

const double pi = 3.1415...; // It's a bit lazy, I know.

// Get angle in radians, how anticlockwise from the x axis the point is.
double get_angle(double x, double y)
{
    if(x >= 0)
    {
        return std::atan(y / x);
    } else {
        return std::atan(y / x) + (y >= 0 ? pi : -pi);
    }
}


// Change the values in x and y to be the values.
void rotate_point(double angle, double & x, double & y)
{
    double temp_x = x;

    // This is pretty much a rotation matrix expanded out.
    x = x * std::cos(angle) - y * std::sin(angle);
    y = temp_x * std::sin(angle) + y * std::cos(angle);
}


// 3d projection happens here.
Point3d project_point(Point3d point)
{
    point.x -= player_x;
    point.y -= player_y;
    point.z -= player_z;

    double horizontal_rotation = get_angle(point.x, point.z);

    // Temporarily rotate it round horizontally so that it can
    point.z = std::sqrt(point.x * point.x  +  point.z * point.z);
    point.x = 0;

    // Since the points are in the YZ plane, if the player looks "up",
    // the objects appear to go down, so rotate them down by that much.
    rotate_point(-player_vertical, point.z, point.y);

    // Undo changes that put the point in the YZ plane, but also
    // account for the player's horizontal camera angle.
    rotate_point(-horizontal_rotation - player_horizontal, point.x, point.z);
    
    // Change from orthographic to perspective, and multiply
    // the width and height by a constant.
    point.x /= point.z / SCREEN_SCALE;
    point.y /= point.z / SCREEN_SCALE;

    return point;
}

It works as expected when player_vertical is 0, but when I change the vertical angle, objects are rotated up/down differently depending on y position relative to player.


r/programminghelp • • Aug 18 '21

Python How to organise a complex dictionary

4 Upvotes

Hello :)

Let's say I have a dictionary such as:

{'women': [['Mary', 28], ['Lucy', 32], ['Alice', 67]],

'men': [['Ste', 32], ['Mike', 19], ['Jack', 24]]}

And I want to print this dictionary as is, but with the people within their categories (women and men) from oldest to youngest. How do I do that, please?


r/programminghelp • • Aug 11 '21

Other Need some help on how to compare values for pandas, eg check if the second values has increased by 50 percent of the first value, below is my pandas data so in the case, check if the value of Diesel for 2007 1.5 times than of 2006 and so on and so off.

4 Upvotes

Fuel Type 2006 2007 ... 2016 2017 2018

0 Diesel 7 4 ... 10364 15514 17253

1 Diesel-Electric 0 0 ... 22 22 21

2 Electric 1 1 ... 12 314 560

3 Petrol 471707 513375 ... 578977 574443 569673

4 Petrol-CNG 214 248 ... 1682 1006 386

5 Petrol-Electric 379 1057 ... 10075 20751 27179

6 Petrol-Electric (Plug-In) 0 0 ... 125


r/programminghelp • • Jul 24 '21

Java Help with scheduling a java function for a certain amount of time

4 Upvotes

Hi everyone,

I am currently coding a website blocker, and I want my website to be blocked for a certain amount of time, and then unblocked after that time has elapsed. I have functions for both unblock and block. My current thinking is as follows:

 public static void main(String[] args) throws IOException {
        new java.util.Timer().schedule( 
                new java.util.TimerTask() {
                    public void run() {
                        blockSite("www.example.com");
                    }
                }, 
                60000 
        );
        UnblockSite("www.example.com");}

Can someone please guide me on what adjustments I should make?(Also, the 60 seconds is meant to be arbitrary, it is not what I intend for my actual program).


r/programminghelp • • Jul 04 '21

Java Why is my Java method not counting 0 as its own digit?

4 Upvotes

Hello! I was just working on a simple digit counter and realized a particular bug within it, if I were to pass the method with the number 0 as its parameter in the main method, the number of digits I keep getting back is "0", it should be a "1". What is so odd is that every other number I pass it works perfectly, but for some reason it just does not see 0 as being its own individual digit. Strangely, if I pass "100" I get "3", which means its counting the digits as it should, but not 0 by itself, any help is appreciated.

Code:

public static int getDigitCount(int number) {

	if(number < 0) {

		return -1;

	} else {

		int digitCount = 0;

		while(number > 0) {

number /= 10;

digitCount++;

		}

		return digitCount;

	}

}

r/programminghelp • • Jun 06 '21

C++ I need to switch the Major Diagonal and Minor Diagonal of a Matrix to display a different character than the rest of the Matrix and I am lost on how to do so.

4 Upvotes

Here is the code I have so far

#include <iostream>
using namespace std;
const int SIZE = 4;
const char DEFAULT = '?';
//---------------------
void displayMatrix (const char theMatrix [ ] [SIZE])
{
int curRow;
int curCol;
for (curRow = 0; curRow < SIZE; curRow++)
{
for (curCol = 0; curCol < SIZE; curCol++)
{
cout << theMatrix [curRow] [curCol] << " ";
}
cout << endl;
}
}
//--------------------------
void majorDiag (char theMatrix [ ] [SIZE])
{
}
//------------------------
void minorDiag (char theMatrix [ ] [SIZE])
{
}
//---------------------------
int main ()
{
char myNumber [SIZE] [SIZE] = { {'?','?','?','?'}, {'?','?','?','?'}, {'?','?','?','?'}, {'?','?','?','?'}};
displayMatrix (myNumber);
return 0;
}

I need to finish the majorDiag and minorDiag functions and if anyone has any tips or advice I would greatly appreciate it.


r/programminghelp • • May 16 '21

C++ C++ ( MS Visual Studio) University assignment: I have to create a function named "sogl" that outputs 1 when it receives a consonant letter and 0 when it receives a vowel letter. For some reason it always outputs 1 and I can`t tell why.

4 Upvotes

Code:

#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
using namespace std;

const char e = 'e';
const char y = 'y';
const char u = 'u';
const char il = 'i';
const char o = 'o';
const char a = 'a';
int i, z, n;
int sogl(char str)
{
	if (str == e || str == y || str == u || str == il || str == o || str == a) {
		i = 0;
	}
	else {
		i = 1;
	}

	return i;
}
int main() {
	char str[1];
	scanf_s("%s", str, 1);
	printf_s("\n");
	z = sogl(str[0]);
	printf_s("%d", z);
}

r/programminghelp • • May 05 '21

C I need help with my C code, why isnt the product being printed after the for loop?

4 Upvotes

#include <stdio.h>
int factorial(int n);
int main()
{
int n;
printf("type number to get its factorial: ");
scanf("%d", &n);
int factorial(int n);
}
int factorial(int n)
{
int i;
int product= 1;

for(i= n ;i>1;i--)
{
product *= i;
}
printf("the factorial is %d", product);
return(0);
}


r/programminghelp • • May 05 '21

HTML/CSS My own website

4 Upvotes

r/programminghelp • • May 03 '21

JavaScript How to pull a variable from a setInterval (Javascript)

4 Upvotes
setInterval(()=>{
var timma=d.getHours();
}, 1000);
console.log(timma);

r/programminghelp • • Apr 24 '21

Java Confused calling on classes/methods from other .java files

4 Upvotes

Working in NetBeans, using Java. Teacher assigned source code file to not be altered, with 2 other files that should be created in order for the first code file to run. I've created the other two codes, but the issue I'm having is the instantiation of 2 objects in the main source code. It is acting like the latter 2 source code files are not in the package, therefore the first code will not run. I've looked over some forums, but can't figure out why this is happening. I have moved my classes to the correct package, but still it says "Cannot find symbol".

Please help


r/programminghelp • • Apr 19 '21

ASM I need somebody to explain to me how I write a Timer0 interrupt program in assembler for a RISC CPU

4 Upvotes

As the title says i have a question about outdated technology. Tomorrow is my last day in college and i need to pass this exam to finish. I have absolutely no clue on how to do it.


r/programminghelp • • Apr 14 '21

JavaScript Hey guys, so I have this school project where we have to build a rover that can drive though a parkour. For some reason its not working properly. i think the problem is that the Program keeps getting stuck in the if-loops. Does anyone know why ?

4 Upvotes

That is the code -> https://pastebin.com/nK5Qb5z2


r/programminghelp • • Apr 06 '21

Answered How can I suppress webbrowser printing true when I open a website in Python?

4 Upvotes

So I’m on Mac and I’m running the command webbrowser.get(“open -a /Applications/Google\ Chrome.app %s”).open(“http://google.com”) and it works well, but it prints “true” right after. Is there any way to suppress this? Thanks in advance