Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I haven't had the chance to look through this code in detail, but two things immediately strike me:

  • The use of <conio.h>. This is a non-standard library which is specific to certain ancient MS-DOS and Windows compilers, and won't be supported by any modern compiler library.
  • The declaration of main() as a void function. This is entirely non-standard, and should be avoided - while older compilers sometimes allowed it, and the older versions of the standard permitted it, modern compilers will invariably catch it as an error.

In addition, the indentation is seriously messed up, though that could be the result of pasting the code into the post.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

A forum is just a central meeting place, or (in this case) a place where you can talk with others about some topic. More specifically, it is a synonym for "message board".

In other words, you are already using the forum.

The link Dani gave should help you with this specific forum (Daniweb).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I've been working on the GUI portion of my C++ Connect-N game project, and have gotten it to would could charitably be called a working state. However, the game AI, not to put it to finely, stinks.

I was wondering if anyone here has more experience in implementing a minmax algorithm, and can offer any advice on how to get it to play a suitably challenging game.

The minmax code is:

#ifndef __CONNECTN_AI_H__
#define __CONNECTN_AI_H__ 1

#include <vector>
#include "connectnboard.h"

namespace ConnectN
{

    typedef intmax_t Weight;
    typedef uint8_t Depth;
    const Weight infinity = INTMAX_MAX, neg_infinity = INTMAX_MIN;

    struct Node
    {
        Board board;
        Grid_Size column;
        Weight weight;
        Depth depth;
        Node(const Board& b, Grid_Size c, Weight w, Depth d): board(b), column(c), weight(w), depth(d) {};
        Node(const Node& n);
        void operator=(const Node& n);
    }; 


    class Solver
    {
    private:
        Board& board;
        Depth search_depth;
        Node negamax(Node node, Depth depth, Weight alpha, Weight beta, Weight color);
        std::vector<Node> enumerate_moves(Node node);
        void order_moves(std::vector<Node>& children);
        Weight evaluate_move(Node& node);
        Weight evaluate_node(Node& node);
        Weight weight_column(Grid_Size c);

    public:
        Solver(Board& b, Depth d);
        Grid_Size move();

        friend class Board;
    };
}

#endif

and

#include <algorithm>
#include <chrono>
#include <cmath>
#include <random>
#include "connectnboard.h"
#include "connectn_AI.h"

namespace ConnectN
{

    /**
     * 
     *
     */
    Node::Node(const Node& n)
    {
        this->board = n.board;
        this->column = n.column;
        this->weight = n.weight;
        this->depth = n.depth;
    }


    /**
     * 
     *
     */
    void Node::operator=(const Node& n)
    {
        this->board = n.board;
        this->column = n.column;
        this->weight = n.weight;
        this->depth = n.depth;
    }


    /**
     * 
     *
     */
    Solver::Solver(Board& b, Depth d = 3): board(b), search_depth(d)
    { …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

We would need a lot more information than that to be able to help you with it, starting with the code in question and the error you are getting.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

If you don't mind me asking, how is it that you are writing new VB 6.0 code in 2022? I would strongly advise against trying to beat that dead horse any further, if you have any choice in the matter.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Several of us have VB6 experience, but for most of us it would be several years since we've used it - VB6 was released in 1998 and support for it was mostly discontinued by 2008. It is extremely inadvisable to write any new code using VB6 in 2022.

Also, while you appear to have tried to format your code, you need to know that the inline code formatting using the backtick doesn't span multiple lines of code. For multiline code snippets, you need to indent the code by four spaces. The Cod Block tool ("</>") on the window toolbar will do this automatically for you.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

i have posted the code.its a bit bulky because i had to repeat one function four times. i know there is a shorter way to do this but i have not figured out how.

One thing you can do is, rather than having separate final_searchn and newest_listn variables, use a list of lists for each of those. For example:

final_search = []
for i in range(3):
    final_search[i] = []
    for item in my_new_list[:index_list[0]]:
        final_search[i].append(item)
    final_search[i] = final_search[i][::-1]

As for the function search_engine(), I would parameterize new_input:

def search_engine(my_new_list, new_input):
    # ...


def update_list():
    f = open("list_file.txt", "r")
    print(f"Last Updated Liist: {f.read()}")
    enter_input = float(input("Please enter your input: "))
    my_list.insert(0, enter_input)
    my_list.remove(my_list[-1])
    my_new_list = my_list
    print(f"Updated List: {my_new_list}")
    for ni in ['3', '4', '5', '6']:
        search_engine(my_new_list, ni)

    f = open("list_file.txt", "w")
    f.write(str(my_new_list))
    f.close()
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

There are two approaches you can take: you can either make scP1 and scP2 globals by moving their declarations to the top level outside of the main() function or - preferably - pass them as references to Score() so that they could be updated.

Note that similar issues exist for the readCards() function; you need some way to return the values read in from the file to the main() function. This is where that damnable requirement for parallel arrays (as opposed to packing all values into an single vector<> of a data structure as any sane coder would do) becomes a serious headache - with the parallel arrays, not only do you need to synchronize them manually, but you have to pass each of them individually to each function that uses them. The fact that it uses primitive arrays rather than vector<>s doesn't help, either. Parallel arrays is simply a very bad design for this sort of data structure, and I frankly would complain to the instructor that the textbook is teaching poor techniques.

Anyway, here is what I recommend (warning, not tested):

int Score(int&, int&, int ,int ,int [],int []);

//scores for each round
int Score(int& scP1, int& scP2, int IDcardP1,int IDcardP2,int sctype[],int scsystem[]){
    cout << "The winner for this round is " <<endl<<endl;
    if (sctype[IDcardP1]>sctype[IDcardP2])
    {
        cout << "  PLAYER 1  " <<endl;
        scP1+=10;
        cout<<endl;
    }
    else
    {
        if (scsystem[IDcardP1]>scsystem[IDcardP2])
        {
            cout << "  PLAYER 1  " <<endl;
            scP1+=10;
            cout<<endl;
        }
        else
        {
            cout << "  PLAYER 2 …
isyae commented: i already done with the function scores, but for the function finalscore i still didnt get the total score based on function scores +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Fortunately, the assignment gives a good deal of detail as to how to go about it, and seems focused on how well you understand basic OOP development. From the assignment, you know that:

  • You'll have a class called Account
  • Account objects will have member (instance) variables for the account number; the account type; the account balance; the account holder's name; an optional joint account holder's name; and the account transfer status.
  • The Account class has member functions to act as getters and setters for each of the member variables.
  • Account will have two sub-classes, which could be called something like SavingsAccount and PersonalLoanAccount, both of which extend Account in specified ways.

This seems to me to be the place to start.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

If I might recommend a bit of an improvement:

void ShowCardP1(int cardP1, string cardName[], string p_code[], string type[], string plusMode, string system[]) {
    cout<< "Product code: " << p_code[cardP1] << "  " << endl;
    cout<< cardName[cardP1] << "  " << endl ;
    cout<< "Type: " << type[cardP1] << "  " << endl;
    cout<< "PlusMode:" << plusMode[cardP1] << endl;
    cout<< "System: " << system[cardP1] << endl;
}

Mind you, if it weren't for the (rather absurd) instructions to use parallel arrays, I would instead declare a struct type to hold this information:

struct CardDetails {
    string name, code, type, mode, system;
} cards[SIZE] = {{"Abyss Devolos", "F0647", "Balance", "NA", "SpeedStorm"},
                 {"Ace Dragon", "E7609", "Attack", "NA", "HyperSphere"},
                 // ... etc. 
                };

// ...

void ShowCardP1(int cardP1, string cards[]) {
    cout<< "Product code: " << cards.code[cardP1] << endl;
    cout<< cards.name[cardP1] << endl ;
    cout<< "Type: " << cards.type[cardP1] << endl;
    cout<< "PlusMode:" << cards.mode[cardP1] << endl;
    cout<< "System: " << cards.system[cardP1] << endl;
}

This is probably a bit ahead of where your course is right now, however.

isyae commented: aaaa thankyouuu sooo muschhhh +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I spent far too much time on this, but I worked out a usable password sign-in process that you may want to look into. It uses a third party library, passlib, which can be installed using pip install passlib.

import getpass
from passlib.context import CryptContext

# some of the code taken from the web page
# https://blog.teclado.com/learn-python-encrypting-passwords-python-flask-and-passlib/

def init_pwd_context():
    return CryptContext(
        schemes=["pbkdf2_sha256"],
        default="pbkdf2_sha256",
        pbkdf2_sha256__default_rounds=30000
    )

def encrypt_password(pwd_context, password):
    return pwd_context.hash(password)


def check_encrypted_password(pwd_context, password, hashed):
    return pwd_context.verify(password, hashed)


def add_account(fname, pwd_context, username, password):
    """ Adds an account to a file of 'username, password' pairs.
        Simply appends the new information to the end of the file, if a username already
        exists the new one shadows the old information."""
    file = open(fname, "a")
    file.write(f"{username}: {encrypt_password(pwd_context, password)}\n")


def collect_accounts(fname):
    """ Reads a file with 'username,password' pairs and returns a dictionary with the pairs."""

    accounts = dict()
    try:
        file = open(fname,"r")
    except FileNotFoundError as e:
        return accounts
    account_strings = file.readlines()
    for acct in account_strings:
        username, password = acct.split(': ')
        accounts[username.strip()] = password.strip()
    return accounts


def get_user_pwd(): 
    """ Reads in a username and password."""
    username = input("Username: ")
    password = getpass.getpass()
    return username.strip(), password.strip()


def login(accounts, pwd_context):
    """ Log user in, returning the user name."""
    while True:
        username, password = get_user_pwd()

        if (username in accounts):
            if check_encrypted_password(pwd_context, password, accounts[username]):
                return username
        print("Username or password incorrect.")



if __name__ == "__main__":
    pwd_context = init_pwd_context()
    accounts = collect_accounts("Accounts.txt")
    a_or_l = input("A)dd or L)ogin? ").upper()
    if a_or_l == 'A':
        username, password = get_user_pwd()
        add_account("Accounts.txt", pwd_context, username, password)
    elif a_or_l == …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Unfortunately, there's really no way to read Python code when the indentation has been lost. I'll try to puzzle out your intentions here, but it isn't straightforward. As it is, I can't even tell if this is all supposed to be one function, or the function followed by some top-level code. As best as I can determine, you intended the code to read like so:

def login(): 
    username = input("Enter username: ")
    password = input("Enter password: ")
    file = open("Account.txt","r")
    account = file.readlines()

    access = False
    while access == False:
        for user in account:
            if username in user and password in user:
                login = user.strip("\n")
                login = login.split(",")
                if username == login[0] and password == login[1]:
                    access = True
                    print("Welcome", username)
                else:
                    print("Username or Password is incorrect, try again.")

            else:
                print("Username or Password is incorrect, try again.")
                username = input("Enter username: ")
                password = input("Enter password: ")

        if access == True:
            break

This forum uses Markdown, so in order to preserve the formatting of your code, you would indent teach line by four spaces. The Code Block button (</>) will open a separate sub-window to make this easier to paste the code into the message while preserving formatting.

As an aside, you generally don't want to have the text of a password to echo to the console, to prevent people from shoulder-surfing. There is a standard password library, getpass as part of the Python standard library, for precisely this purpose.

On a related note, you seem to be using …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I can see a number of issues with the code as given.

  • You define a class Shapes but then declare Circle as a subclass of Shape. The names need to match in order to be valid.
  • You never #include the header Shapes.h in the Circle.h header.
  • You define Circle middle as an instance variable of Circle itself, which leads to a recursive definition. While one can have a recursive definition using a pointer (e.g., Circle* middle;), having an object of the type inside the class definition isn't valid.
  • Point::getX(), Point::getY(), and Point::Print() are all instance methods rather than class methods. There would need to be a Point object for them to be applied to. Applying an instance method is in the form myPoint.getX().

Presumably, what you want to do is have middle as a Point instead, and apply those methods to middle.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Uhm, 'struggle'? I have no idea what that refers to in this context. OTOH, void just means a function doesn't return a value, or conversely, that a pointer doesn't have a type.

Mind you, I don't think this code would even compile under most compilers today, or at least would give few warnings about it. The main() function must - I repeat, must - be declared as int in C++, and return some sort of value, no ifs, ands, or buts. Furthermore, <string.h> was renamed to just <string> in 1998, and most modern compilers won't allow that header - or if they do, they assume you want the C string library (renamed to <cstring> in modern C++, but still sometimes used in older code) rather than the C++ string class library. If you don't mind me asking, what compiler are you using?

Getting to the problem at hand, I would suggest that you have separate wincount variables for each of the teams; as it is, you are just counting how many games were played (except in the cases of ties). The simplest way to do this would be to declare two variables, wincount1 and wincount2, and use those to count the wins for the individual teams, rather than the aggregate of both.

    cout << "\tTeam " << team2 << " Points: ";
    cin >> p2;
    cout << "================================\n";

        if (p1 > p2)
            {
                cout << "Winner: Team " << team1 << endl;
                wincount1 += 1;
            }
        else if (p1 …
rproffitt commented: +1 for the win. +16
Jash_1 commented: It worked! I've derived some codes and it finally run. Thank you very much +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Definitely homework, apparently from University of Technology of Jamaica (which fits with the reference to Norman Manley Airport, a real airport in Kingston). If that link is anything to go by, the project is meant to be solved in Java.

If so, I guess my first question to the OP is, why tag it as C++ if it needs to be done in Java?

My second question is, what have you tried doing on the project so far? Please post your code in your messages, or at least give us a link to an offsite repo which we could view (and yes, I recommend having all programs placed into version control and stored on an offsite repository on a host such as GitHub, even homework problems).

We cannot and will not provide code for you, but we can help you by giving advice on how to fix the code you have written.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

If you want it to run in a browser, then yes, you almost certainly want to use JavaScript. While there are other languages which can be used, such as TypeScript or ClojureScript, they all get translated into JavaScript anyway.

There are many video tutorials on this topic, and many web pages as well. I would go over a few of them to see what you can get out of them, then apply that to your own game.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, we don't do other people's homework for them. Second, we don't do other people's homework for them. And third, we don't do other people's homework for them. Sensing a pattern here yet?

No one here will simply hand you a solution on a silver platter. If you show us what you've done, what you've tried to do, and what problems you've had with it, then we'll be happy to help. If you have specific questions, we can answer them, or at least point you in the right direction. If you have a program with a bug you can't swat on your own, we'll be glad to assist, so long as you pay attention to the forum rules and post sensible questions in an intelligent manner that we have some reasonable hope of answering.

But just cutting and pasting an assignment into a message, without even prefacing it with something like, "I have this homework problem that I can't solve...", is likely to get you booted from the message boards here and elsewhere - if you're lucky. What happens to you if you are unlucky is... well... let's just say that this guy probably won't be trying that again, on that forum or this one.

We take this issue seriously here. Very seriously. Asking us to do homework for you is a grave breach of academic ethics on your part, and actually doing so would be an even bigger breach on ours (not that this …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

There is a developer on the OSDev forum, David Cooper, who managed to do something like this for his OS project, though I am pretty sure he started off cross-developing his toolkit. He created what he describes as a sophisticated suite for editing code in hex, though presumably if you really wanted to you could do it in binary.

He's a bit of a crank, but that's true of everyone on that forum, myself included.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The fact that the code given is incomplete, with no main() function, makes it hard for us to judge whether it works at all.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

From what I've read, MIPSMARK is intended for checking and grading MIPS assembly language programs. Are you compiling the C code to MIPS assembly, and if you are, with what compiler and compiler invocation?

Where is MIPSMARK available from? Do you know of a download site for it, or a documentation page? Also, could you tell us which book the assignment is from?

rproffitt commented: OP supplied C style code and then as you note something about assembler check app but left out the story and more. +16
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Honestly, it is so ubiquitous as a sub-set of modern programming techniques that it isn't really even a debate any more. Pretty much all modern programming is 'structured' in the sense it was originally meant, it is just that more elaborate design approaches have subsumed it.

Or to put it another way: outside of assembly programming and certain specialized C code, when was the last time you saw a general unconditional jump (i.e., goto)? How many modern languages even have a goto statement? Even the unconditional jumps that are still common (exceptions, break, continue, etc.) are for specialized cases, and are still 'structured' in how they are used.

As for structured programming as a specific paradigm, it is still practiced in C programming in exactly the sense Dijkstra meant. C doesn't explicitly support either OOP or FP, and does have a goto, and yet it is exceedingly rare to see it used.

rproffitt commented: Do I have a break for you? Goto Park Place, get of jail card. +16
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The structure tag is optional because there are instances where you want a one-off structure;

struct {
    int foo;
    char bar[4];
} my_unique_data_structure;  // only struct of this form

The tag is for when you want to name the structure template or type.

struct quux {
    int baz, bang, zing;
};

struct quux whoopie;

You can also declare instances of a named structure following the structure definition, for cases where you know ahead of time that you need at least one structure of that type:

struct quux {
    int baz, bang, zing;
} whoopie;

// later ...
struct quux flarp;

I hope this makes it a bit clearer.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

According to this post, the solution is to operate on playlist directly rather than extracting the "items" sub-dictionary.

razstec commented: Excellent as always +3
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Is there a specific reason you need to ensure that the values are positive?

As per RProffitt's suggestion, here is how you would loop on the input to require that the input value is positive.

#include <iostream>

using namespace std;

int main()
{
   int X = -1;
   int Y = -1;
   while (X < 0)
   {
       cout<<"please enter a positive value for X";
       cin>>X;
   }
   while (Y < 0)
   {
       cout<<"please enter a positive value for Y";
       cin>>Y;
   }
   float result;
   result=4*X^3+Y^3-4;
   cout<<"the result of Z="<<result;
   return 0;
}

A simpler alternative is to use abs() (which requires you to #include <cmath>) to force the value positive regardless of whether it was negative or not. However, looping on the input is advisable in any case, to hand the instance where the input is a string.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

There are already functions for saving games and loading saves in the code, so I assume that there is some problem with those functions. Could you please explain what is actually happening?

Does the program fail to compile, or compile with warnings? Is the program crashing when you try to save and/or load? Does it save, but incorrectly? Does loading fail restart the game at the saved point? Are there any error messages?

BTW, <conio.h> is not a standard C library, it is specific to a few older Windows compilers such as Turbo C. I would recommend avoiding it, even if your intention is to run purely on Windows. Similarly, you are using the ANSI character set for extended and control characters, which will only work properly with certain settings even under Windows. I would recommend the windows port of NCurses instead, as that should work in all circumstances; or conversely, moving out of the console entirely and writing the program as a Windows application. Finally, using system() presents a number of security holes, and is best avoided as well.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

If you want to learn how to program in PHP (which I think is what you really mean), then you would want to find a good book or tutorial on the topic. It isn't really something you can just pick up, even if you are familiar with other programming languages.

I am by no means an expert in PHP, but I would recommend as a starting point the book Learning PHP, MySQL & JavaScript: A Step-by-Step Guide to Creating Dynamic Websites by Robin Nixon. There are also several free online tutorials on the topic, but I don't know personally which ones are worth your trouble.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, we don't do other people's homework for them. Second, we don't do other people's homework for them. And third, we don't do other people's homework for them. Sensing a pattern here yet?

No one here will simply hand you a solution on a silver platter. If you show us what you've done, what you've tried to do, and what problems you've had with it, then we'll be happy to help. If you have specific questions, we can answer them, or at least point you in the right direction. If you have a program with a bug you can't swat on your own, we'll be glad to assist, so long as you pay attention to the forum rules and post sensible questions in an intelligent manner that we have some reasonable hope of answering.

But just cutting and pasting an assignment into a message, without even prefacing it with something like, "I have this homework problem that I can't solve...", is likely to get you booted from the message boards here and elsewhere - if you're lucky. What happens to you if you are unlucky is... well... let's just say that this guy probably won't be trying that again, on that forum or this one.

We take this issue seriously here. Very seriously. Asking us to do homework for you is a grave breach of academic ethics on your part, and actually doing so would be an even bigger breach on ours (not that this …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Having taken a closer look at it, I can see that there are serious problems with how the code is edited and structured. Aside from the fact that it is completely un-formatted, I found that a section of code which appears to have been meant to be part of the main() function somehow got misplaced at the end of the code. I have managed to edit the code to at least the point where it compiles; whether it works correctly is up to you to determine.

For the record, I compiled the code in GCC with the shell invocation:

g++ -Wall -Wextra -Werror simple-sci-calc.cpp -o simple-sci-calc

The updated code is:

#include <iostream>
#include <cstring>
#include <cmath>

void Power(float,float);
void Sine(float);
void Square(float);
void Cos(float);
void Tan(float);
void Log(float);
void Baselog(float);

int main()
{
    int input;
    std::cout << "CHOOSE BETWEEN SCIENTIFIC AND SIMPLE CALCULATOR:" << std::endl;
    std::cout << "[1] Scientific" << std::endl << "[2] Simple" <<std::endl;
    std::cin >> input;

    switch(input) 
    {
    case '1':
 //       float a,b;
        int z;

        std::cout<<"WHAT YOU WANT TO FIND: "<<std::endl;
        std::cout<<"Press '1' for Power: "<<std::endl;
        std::cout<<"Press '2' for Sin: "<<std::endl; 
        std::cout<<"Press '3' for Square: "<<std::endl; 
        std::cout<<"Press '4' for Cos: "<<std::endl; 
        std::cout<<"Press '5' for Tan: "<<std::endl;
        std::cout<<"Press '6' for Log: "<<std::endl;
        std::cout<<"Press '7' for Base Log: "<<std::endl;

        std::cin>>z;
        switch(z)
        {
        case 1:
            std::cout<<"Enter the Number for Calculating its Power: "<<std::endl;
            int a;
            std::cin>>a;
            std::cout<<"Enter the Power for a Number: "<<std::endl;
            int b;
            std::cin>>b;
            Power(a,b);
            break;

        case 2:
            std::cout<<"Enter the Number for Calculating SIN: "<<std::endl;
            std::cin>>a;
            Sine(a);
            break; …
Husnain_6 commented: Thanks Sir it helped alot +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Could you please elaborate on what you mean when you say "it is not running"? Is it failing to compile? Does it compile, but crash? Please give details about the failure mode.

Also, the header <conio.h> isn't valid in any modern compiler, being specific to the now-ancient Turbo C++ compiler suite. If you are still using Turbo C++, STOP. You are doing yourself a disservice by learning an pre-standard version of C++.

Similarly, the C headers <math.h> and <string.h> are renamed <cmath> and <cstring> in modern C++.

rproffitt commented: I said similar to someone and the reply was "But Turbo C++ is free." +16
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Oops, I dropped a dollar sign in there. Sorry about that.

    $stmt = $conn->query("INSERT INTO ronin(phrase, password)VALUES(?, ?)");
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The procedure mysqli_query() has the following signature:

mysqli_query(mysqli $mysql, string $query, int $result_mode = MYSQLI_STORE_RESULT)

It takes either two or three arguments, with the first argument being the database connection handle. Thus, you probably want the call to be:

    $stmt = mysqli_query($conn, "INSERT INTO ronin(phrase, password)VALUES(?, ?)");

Alternately, you could instead use the OOP model to call the method query() like so:

    $stmt = conn->query("INSERT INTO ronin(phrase, password)VALUES(?, ?)");

I suspect that this was what you intended to do in the first place.

On an unrelated note, please do not post images of code snippets to the forum, but instead cut and paste the code into a code block using the Code Block button ("</>" in the editing window icons). This makes it far easier for respondents to read, and to make code changes.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

My first comment is more of an aside, but I was puzzled by the mixing of C stdio and C++ iostreams. I would pick one or the other, not both. Similarly, why use CStrings rather than C++ string objects? It isn't particularly relevant, but it gives the impression that the original coder (you, presumably) was more comfortable with C than C++.

Also, the usual caveats about using globals apply.

Finally, I think there are issues with the entire design of this, starting with why you aren't using a dedicated logging library in the first place. I assume that this is a class assignment, however, meaning that this option is closed to you.

Getting back to the problem at hand, lets look at the first place the segfault is occurring:

static bool write_to_outputfile(char* outputfile,char* content)
{
    bool write = false;
    for(const struct Fileoutput fo : vect_fileoutputs)
    {
        if(strcmp(fo.filetag.c_str(),outputfile) == 0)
        {
            printf("Writing [%s] to [%s]\n",content,outputfile);
            std::fstream* fs_write;
            fs_write = fo.filepointer;
            *fo.filepointer << content; 
            write = true;
            break;
        }
    }

    return write;
}

Here, the problem is that you are attempting to dereference a struct as a pointer. the correct form should be

            fo.*filepointer << content; 

With the indirection operator on the fstream pointer (EDIT: I originally dropped the indirection pointer outright, then noticed that it was still needed on the fstream pointer). I would assume that you've tried that, but sometimes it is the most obvious errors which are hardest to spot - I once spent two weeks chasing …

rproffitt commented: Thanks for this. It does seem to be a curious mix of c and c++. +0
sankar2000 commented: good explination, i want something simple that is why i dont use a log library, and indeed, is a mixing of c and c++, i should rewrite +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

We would need to see the code in order to determine anything about it. Please post your code (in the message directly, using the Code Block '</>' button), or at least post a link to your public repository, if you have one (which is highly recommended, even if it a small personal project). Please do not use pastebin or anything similar, nor should you post a screenshot - we would need to see all of the code, in an editable form.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Not to be overly pedantic, but: .NET Framework is the library and runtime support system used by a number of different Microsoft languages. Visual Basic.NET is one language, C# is another, F# is yet another. The same .NET libraries work for all of them.

There may not be examples of how to use NAudio in VB.NET in the documentation, but it should be possible to do so with minimal effort. It is simply a matter of figuring out how to use the library classes and functions from VB.NET.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I would definitely try putting the "Days" constant string into a Label next to the ComboBox in question. As it is, you'd need to parse the string into the part with the numerical value, and the part with the "Days" substring, and you would need to do it any time you want the numeric value. It can be done, but it isn't really worth the effort, and in any case the Label would probably be clearer for the user.

Not to be too much of a nuisance about it, but it might help if we knew more about the program as a whole, in case there might be a better solution which isn't obvious just from this one small piece of the puzzle.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

In one way, it depends on whether you are targetting iOS or Android. For the former, you would natively use Swift, while for the latter you would natively use Java.

However, there are a number of tools for cross-platform development, of varying quality, some of which work with C#, JavaScript, Clojure, Python, or even VB.Net, so you have a variety of options for this. While it wouldn't be ideal, you can work in VB.Net if you choose (though not VB6, which is long, long out of support).

My own choice would be Clojure, but then I am insane like that. :-)

As for database use, it would depend on whether you need the database to be local to the mobile device, or remote on a server. For device-local databases, you would usually use SQLite, which is somewhat more limited than a full SQL RDBMS. Server databases can use whatever you choose, more or less, but you'd need some means of connecting to it remotely, which usually means some sort of server-side programming in addition to the SQL database.

rproffitt commented: My thought is VB6 is Blue Pill, Clojure and such is Red Pill. +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Just as an aside, since you know that it is in the range 0..30, have you considered declaring value as Byte (and casting the string using CByte()) ? That would at least help eliminate one possible source of error (since you would never get a negative value).

Perhaps try writing a utility function to force saturation, like this (warning, untested code, it has been a while since I coded in VB.Net):

Public Function CByte_Saturate_Range(data As String, min As Byte, max As Byte) As Byte
    Dim value As Byte
    Dim swap As Byte

    If min = max Then
        Return min
    End If

    If min > max Then
        swap = min
        min = max 
        max = swap
    End If
     ' convert to a Short first, then force it to a positive absolute value
     ' before converting it to Byte
    value = CByte(Math.Abs(CShort(data))
    If min > value Then
         value = min
    ElseIf value > max Then
         value = max
    End If
    Return value
End Function

You would call it like so:

    value = CByte_Saturate_Range(Label10.Text, 0, 30)
    If value > 0 Then
        value = value - 1
    Else
        Form11.Button5.PerformClick()
        Timer1.Stop()
    End If
    label10.Text = CStr(value)

While this might seem overkill, it would at least separate the logic for converting and saturating the value from that of testing for the timer value.

Actually, let me back up a bit before I finish: why is the timer based on a Label's value in the first place? That might help us understand the wider goal involved.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I can't say if it the main source of the problem, but the line If value >= 0 Then has the test reversed; it should be If value <= 0 Then instead.

This doesn't explain why it fails at exactly zero, but you'd be better off correcting it anyway.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

As Rproffitt said, please make your own new threads rather than resurrecting long-dead ones.

As for the error code, that was explained in detail earlier in this thread: it indicates that you tried to read a number from a file, and got something other than a number, as defined here. The likely solution is to add a check for an end-of-file in the loop, using the function eof().

Though from the screenshot, you might be using Turbo Pascal, where the error indicates a malformed string. The correct solution to this is Don't Use Turbo Pascal.

rproffitt commented: Turbo Pascal is the Blue Pill. +16
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Do you have a program class (i.e., one with a main() method) which you could share with us, so we could test the GamePanel class ourselves? Even a minimal test class would help us.

If you have a public repo you could share with us, that would help immensely. You definitely should be using version control with an offsite repo, if you can, as it is crucial for ensuring the ability to monitor the progress of even small projects.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Before I address the question, allow me to trim the includes list a bit, removing some which are either redundant or not actually valid under standard C++ :

#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;

Mind you, using using namespace std; isn't a great idea either, since it essentially undermines the whole point of having a std namespace in the first place, but for homework it is at least acceptable.

As for the actual question, the first thing I take note of is that there looks to be two off-by-one errors in the sorting algorithm.

        for (int i = 1; i < size; i++)  // should be 'i=0'
        {
            for (int j = 1; j <size-i; j++) // should be 'j=0'
            {

Arrays in C++ are zero-indexed, meaning that the first element of the array arry is arry[0], the second is arry[1], and so forth to arry[size-1]. These off-by-one errors could be the source of the segfaults, though I would have to take a closer look than I have to be certain.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Traditionally, sets are represented as bitfields, which could then be manipulated with the bitwise operators - & for union, | for intersection. Since you know the whole set has at most 20 elements, the representation can fit into a single 32-bit unsigned integer.

Also, would it make more sense to make a class Set to factor all of the intersection and union logic out into one place?

By combining these approaches you'd be saving yourself a great deal of effort, I think.

xrjf commented: Right, only note '&' is for intersection and '|' for union. +8
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Did you have a question, or need assistance in some way?

vaishnavi_13 commented: i need to show the intersection of set a and b & set b and c & set c and set a and union pf set a,b and c in output but it is not displaying. +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You would need some sort of server-side scripting (PHP, ASP.NET, Node.js, Django, Ruby on Rails - something like those) to query the database and insert the dataset into the page before it is served. Even if you do some of the work client-side (e.g., with AJAX), you would still need server-side support for querying the database.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

No one here is going to open up some random Word document in MS Word, where there could be random macro viruses in it.

Fortunately for you, I use LibreOffice instead, and the macros are all disabled. So, let me post the code for you as you were requested to do in the first place:

#include<iostream.h>
#include<stdlib.h>
#include<graphics.h>
#include<math.h>
using namespace std;

int xmax,ymax,xmid,ymid;
class Line
{
public:
  int x1,x2,y1,y2,ch;
  void bss(int x1,int y1,int x2,int y2)
  {
    int dx,dy,x,y,s1,s2,ex,e,i,flag=0,temp;

    dx=abs(x2-x1);
    dy=abs(y2-y1);
    x=x1;
    y=y1;
    putpixel(x+xmid,ymid-y,15);

    if(x2>x1)
      {
        s1=1;
      }
    if(x2==x1)
      {
        s1=0;
      }
    if(x2<x1)
      {
        s1=1;
      }
    if(y2>y1)
      {
        s2=1;
      }
    if(y2==y1)
      {
        s2=0;
      }
    if(y2<y1)
      {
        s2=1;
      }
    if(dy>dx)
      {
        temp=dx;
        dx=dy;
        dy = temp;
        ex = 1;
      }
    else
      ex=0;

    e=2*dy-dx;
    i=1;

    do
      {
        while(e>0)
          {
            if(ex==1)
              x=x+s1;
            else
              y=y+s2;
            e=e-2*dx;
          }
        while(e<0)
          {
            if(ex==1)
              y=y+s2;
            else
              x=x+s1;

            e=e+2*dy;
          }

        switch(ch)
          {

          case 1:
            putpixel(x+xmid,ymid-y,15);
            break;

          case 2:
            if(flag==0)
              {
                putpixel(x+xmid,ymid-y,15);
                delay(1000);
                if(i%5==0)
                  {
                    if(flag==1)
                      flag=0;
                    else
                      flag=1;
                  }
                break;

              case 3:
                if(flag==0)
                  {
                    putpixel(x+xmid,ymid-y,15);
                    delay(1000);

                    if(i%5==0)
                      {
                        if(flag==1)
                          flag=0;
                        else
                          flag=1;
                      }
                    if(i%3==0)
                      {
                        putpixel(x+xmid,ymid-y,15);
                        delay(1000);
                      }
                    break;

                  case 4:
                    if(flag==0)
                      delay(1000);
                  }
                else
                  {
                    if(i%3==0)
                      {
                        putpixel(x+xmid,ymid-y,15);
                        dekay(1000);
                      }
                  }
                break;
              case 5:
                putpixel(x+xmid,ymid-y,15);
                break;
              }
            i =i+1;
            delay(50);
          }
        while(i<=dx);
      }
  };

  int main()
  {
    int gd = DETECT,gm;
    int x1,y1,x2,y2,thick,wy,i;
    Line B;
    cout<<"Enter two end pointsof line:\n";
    cin>>x1>>y1;
    cin>>x2,y2;

    while(1)
      {
        cout<<"\nEnter the Style\n";
        cout<<"1.Simple\n";
        cout<<"2.Dash\n";
        . cout<<"3.Dash dot\n";
        cout<<"4.Dot\n";
        cout<<"5.Thick\n";
        cout<<"6.Exit\n";
        cout<<"Enter your style\n";
        cin>>B.ch;
        if(B.ch==5)
          {

            cout<<"Enter the thickness of line:";
            cin>>thick;
          } …
rproffitt commented: Thanks for your effort here. It does make me wonder how they put in 200 lines of code and only now figured out it was never going to be in Turbo C. +16
vaishnavi_13 commented: So to remove inline what exactly i should do?? +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Correction: the strings would be left-justified, not right-justified.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Wait, what? You mentioned Perl in the thread title, but then you added tags for C, C++, and Python. Which is it?

Also, the description doesn't match the illustrative example. How do you need it laid out?

Assuming you do indeed mean Perl, and that you are in shell rather than a GUI window, then there are several options (Perl always has multiple solutions). The simplest, but also most fragile, approach is to use sprintf() with a suitable format string, like so:

sprintf("%20s%20s%20s%20s", "Time", "Column_1", "Column_2", "Column_3")

This example will print the data right-justified in columns of 20 characters. However, there are a number of better approaches, such as the Text::Column library in CPAN. A quick search on CPAN for 'Column' finds a few others you could try, while a similar search on 'tabulate' finds even more, some of which would probably suit your intended result.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

A quick search finds this list of free books on Python. Of these, I would recommend Think Python personally, though I don't know all of the others so there may be a better one in the list if you check.

As for videos, I would suggest Tech With Tim's "Complete Python Course for Beginners", though I will mention that the full video is rather long.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Let's step back and look at the details, such as

  • What sort of game are we talking about? The mention of tokens makes it sound like it is suppose to be a simulated slot machine or arcade machine, but the 'online billing' part is a bit confusing.
  • What is the time management part for?
  • You tagged both 'JavaScript' and JQuery' in addition to VB.Net. Is the game supposed to be web-facing, and if so, how is it to be hosted? Is the VB.Net part supposed to use ASP.Net scripting server-side?
  • Are you using a Version Control System (e.g., Subversion, Git, Team Foundation Service) and an offsite repo - which you should, even for a small class project like this - and if so, could you give us a link to the repo?

At this point, we don't know enough about the project to even tell what the assignment actually is, never mind the fact that we'd need to see what you have attempted already to be able to give advice.

David_239 commented: And our prof gives us less time to make it +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

If you don't mind me asking, do you have a publicly accessible version-control repository for your code? It would make it much easier for us to review the program, if necessary.

However, I suspect that the problem isn't with the program itself, but rather with the installer - especially if it is in VB6, rather than VB.Net. Maintaining VB6 has become more and more difficult as support for it has dropped away, and Microsoft themselves have been pushing users to migrate to VB.Net for almost 20 years now (.NET Framework being introduced in early 2002). While Windows 10 generally doesn't have a problem with 32-bit programs, Windows 11 support for older programs seems less certain.

What can you tell us about the failure mode? Do they get any error messages?

Have you tested the installer yourself on one or more different machines other than your development platform?

What version of Windows are you developing on, and what versions of Windows are your clients running it on? I am specifically wondering if any of them are running Windows 11.

Also, are any of the clients reporting a problem using new Intel CPUs (the ones with separate performance and efficiency cores)? Some older programs are having problems with the big.LITTLE architecture - especially ones which rely on 32-bit support, as would be necessary for VB6 - and your installer could be as well. I assume that this is unlikely, given how new those systems are, but I thought I would bring it …