Sam Knappenberger
Sam Knappenberger

Reputation: 35

C++ int assignment not working

I've having an issue with my code. It complies fine, but my int week and int days aren't updating properly, and returning to the value 0 in which they were initially assigned. I'm a very novice programmer, and this code is just a snippet of another I'm trying to write. Thanks for any and all help? EDIT: Also, I had to return days by rewriting the basic_order int, it's super inefficent, but I don't know how to do it any other way.

Here's my code.

#include <iostream>

using namespace std;

int BasicMakespan(int &basic_order)

{
    int shirts_left, days, weeks;
    days = 0;
    weeks = 0;
    shirts_left = basic_order - 1000;
    while (shirts_left >= 0)
    {
        shirts_left = shirts_left - 1000;
        days = days + 1;
        if (days == 6)
        {
            days = 0;
            weeks = weeks + 1;
        }
    }
    basic_order = weeks;
    return days;
}

int main ()
{
    int basic_order;
    cin >> basic_order;
    BasicMakespan ( basic_order );
    cout << BasicMakespan << " " << basic_order << endl;
}

Upvotes: 3

Views: 553

Answers (1)

Daniel Frey
Daniel Frey

Reputation: 56863

Maybe you meant to write this:

int main ()
{
    int basic_order;
    cin >> basic_order;
    int result = BasicMakespan ( basic_order );
    cout << result << " " << basic_order << endl;
}

? Because your code is currently printing the address of BasicMakespan, not the result it returns.

Upvotes: 3

Related Questions