C++ warning in function
My function consists of 2 global variables
In case you are wondering what this function does, I'll explain.
The function is made for after the player wins the level. When this happens, they gain XP and coins. For some reason, the program is giving me a warning on the return value
How can I fix this?
The warning is at
return XP, coins;
An extra favor?
I don't want my game to only drop a certain amount of coins or give only 100 XP every single level. How can I change this to be random between a certain amount of numbers?
(if you answer both, i will select your explanation as the answer to this question)
I am not including the entire program due to other possible errors that i may be fixing while awaiting the answer to this question
Oh, I missed the
How can I change this to be random between a certain amount of numbers?
for that, you might be interested in
There's a lot to random number generation, so it can quickly get complicated if you attempt to dive in, so I'd recommend honestly, just ignoring it, and picking a generator.
Check the example at the end, or the quick one I put up here: https://replit.com/@xxpertHacker/random-example.
Currently, you are using C++'s comma operator, which is... practicially useless.
(x, y) evaluates to
(XP, coins) == coins; you're just returning
coins are only mutated within the scope of the function, maybe you wanted to pass by reference?
I'd suggest using a std::pair to return
coins at once.
But more likely, you'd want a global player struct, and you'd mutate
coins as globals instead.
auto is one C++'s type deduction keywords.
I just didn't want to type out
std::pair<int, int>; but that's the type that the
std::make_pair return type is deduced as.
As for the
auto [ experience, coins ] = ..., the
You cannot return two things.
You should do something like this:
sorry I'm dumb
Also your functions should always be lower case bruh
Also you can't assign to a copy, that won't work, assign by reference.