Click here to Skip to main content
15,884,917 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello . I'm kind of a novice at programming and I'm coding a programme that hasn't been finished yrt . The main reason that I'm asking a question about a semi-finished programme is to be sure if this programme is in my level or not.
Is really "Creating objects by using user input" , in the field of "dynamic programming" Or not ?

If it is , please announce me not to continue coding.Thank you.




Actually I was trying this and as I told you , It's half-done:

What I have tried:

#include <iostream>

using namespace std;

int q = 0;

class Good
{
private:
    int name;
    float sell_cost , buy_cost;
public:
    int stock = 0;
};

void name_getter(Good &v[])
{
    cin >> v[q].name;
}

void buy_cost_getter(Good &v[q])
{
    cin >> v[q].buy_cost;
}

void sell_cost_getter(Good &v[q])
{
    cin >> v[q].sell_cost;
}


int finding_desired(string n)
{
    for (int i = 0; i <= q ; i++)
        {
            if ( o[q].name == n )
            {
                return i;
                break;
            }
        }
}


int main()
{
    string command;
    cin >> command;
    Good o[q];
    if ( command == "Define" )
    {
        name_getter(o[q]);
        buy_cost_getter(o[q]);
        sell_cost_getter(o[q]);
        q++;
    }

    else if ( command == "Buy")
    {
        string desired_good_name;
        int number;
        cin >> desired_good_name >> number;
        o[finding_desired(desired_good_name)].stock += number;
    }


    else if ( command == "Delete" )
    {
        string desired_good_s;
        cin >> desired_good_s;
        for (int i = 0; i <= q ; i++)
        {
            if ( o[q].name == desired_good_s &&  )
        }
    }
}
Posted
Updated 12-Dec-22 8:34am
Comments
Dave Kreskowiak 12-Dec-22 13:17pm    
The main reason that I'm asking a question about a semi-finished programme is to be sure if this programme is in my level or not.

Nobody but you can tell you whether you have the skills to do this or not.

As for something we can actually answer, you haven't said anything about what the problem is with the code you posted.
jeron1 12-Dec-22 13:34pm    
At this point, based on your attempted use of arrays and their indexes, and the the fact that the code does not compile, it seems a bit beyond your current level. Try simplifying things, maybe make your class simpler, write a loop that populates an array with data, then write a loop to output the data. Then try doing these things in a function.... build slowly from simpler to more difficult. Perhaps learn how to use a debugger, you will learn a LOT using a debugger.

1 solution

I'm not suggesting that you "abandon ship" and just not continue coding, but ... you aren't really approaching it very well and could use spending some time thinking about the project before you start tapping on the keyboard.

That code doesn't compile: that's one problem - and a relatively simple one under normal circumstances. But you haven't tried to work in "small chunks" so you have built a lot of code based on code that doesn't compile, so you have no idea if it will even work when it does!
And frankly, that code doesn't show much evidence of planning which means you end up with rather a mess to try and get working.

So I'm going to recommend two of my articles for you to read, and hopefully get a better starting point to work from:
How to Write Code to Solve a Problem, A Beginner's Guide[^]
How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^]
Read them, and then start from scratch: design, code a small bit, get it to compile, run it, test it, fix it, test it again. When it works properly move on to add another chunk. It may seem like a slower way to do it, but it saves huge amounts of time in the long run.

So don't give up - just try to work smarter, not harder! You'll get there.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900