Now I'm rewriting my calculator using the stuff you taught me and I ran into a problem, if I use:
1 2 3 4 5 6 7
void getx(signedlonglongint &xprime)
{
if (!(cin >> xprime) || (xprime < 2) || ((xprime - floor(xprime)) != 0))
{
throw runtime_error{"You have to enter a natural number larger than 1!"};
}
}
It doesn't throw the error if I enter, let's say, 3.4. Instead it registers xprime as 3 and carries the 3.4 to the next cin, which is choosing what to do next (you have to enter 0, 1, ... 6, 7), then it throws an error like it's supposed to. How can I throw an error if a number entered is not an integer?
In the line istringstream is {line}; I get an error error: in C++98 'is' must be initialized by constructor, not by '{...}'. What is it supposed to do anyway?
Also, for every usage of throw runtime_error{"Message"}; I get a warning warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]. Does this mean anything?
EDIT: My compiler was using C++98, changed it to C++11...
Yes, it means you forgot to enable C++14, the latest version of C++. Adjust your command line flags so the compiler receives the -std=c++14 option, or if that doesn't work, use -std=c++11 for C++11 instead.
As for why your compiler defaults to using a version of C++ from almost two decades ago, I have no idea.
Do I need 2 separate functions, one to get x and another to get y, or can it be done in 1? I need your code to do the same as cin >> x >> y; if that's possible.
P. S. Going to sleep now, so won't be able to answer you any time soon. Thanks for the help!
I think from my main function I'm passing x and y's references to getxy(), and it is passing those references to input()? But it doesn't work, after "Enter x:" it immediately says "Invalid input, try again.". Also, how would your code have to be changed, to accept, let's say, only single letters instead of numbers?
A program shall contain a global function called main, which is the designated start of the program.
...
The function main shall not be used within a program.