This question already has answers here:
How can I set the decimal separator to be a comma?
(2 answers)
Closed 2 years ago.
So I am at the start of my programming career and I wrote a code for a simple vending machine on C++.
The problem is, when people pay, they need to input their change into the console like: " 0.50€" for 50 cents. The problem is I live in Europe, and most of the people put in commas as floating numbers like "0,50€". The program collapses when this happens. How do I solve this elegantly? With either the program discovering it and mentions their failure so they can type it in correctly or, better, accepts it as a normal floating-point number.
It is a matter of locale settings.
This question may help you in setting the locale you need in your program.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
so recently I was reading a book that teach you how to program in C++ and I am at basic math stuff. I'm not a beginner in C++ but I have seen something strange that I can't find on the internet.
It is a math expression: 5*3(6' 4) and it has a single quote on it. I found didn't know what it was so I checked up on the internet for this and I found only that it is referred as prime. But I don't think it solve my problem and I don't know how correct that is.
Thanks in advance.
EDIT: I want to address all people who commented and answered (and those who will to do the same thing)in this post that I HAVE MADE A BIG MISTAKE. The real math expression was: 5*6(6*4) but my friend's book(which I got this expression) was not printed well and it looked like the one I have wrote in the past. I'm really really sorry about this....
C++14 and up allows single quote ' inside integer literals to allow for grouping digits. Thanks to this, 123'456'789 can be used as more readable equivalent to 123456789.
Depending on a country, it may be also used in mathematical (outside of C++) expressions, although Polish people would rather use 123 456 789 and UK people would use a comma AFAIK - 123,456,789. None of these is valid in C++ (or it would yield results far from expected), but it would be reasonable in mathematical text/formula.
Nevertheless, your example still wouldn't compile. There is no operator between 3 and opening bracket (.
This question already has answers here:
Checking if a double (or float) is NaN in C++
(21 answers)
Closed 4 years ago.
of course I know I should write better code which just not create NaN values.
But is there any casual method to avoid it. I mean something like:
if (!(floatNumber == NaN))
// do some stupid function
else
return;
But it doesn't work for me. I also tried floatNumber==null, but also no result.
Could you please help me?
To test whether a number is NaN, you can use the standard library function std::isnan.
This question already has answers here:
Using Regex to generate Strings rather than match them
(12 answers)
Reverse regular expression, create string from regex
(1 answer)
Closed 9 years ago.
Or "How can I RegEx in reverse?"
specifically I want to take a regex such as wks[0-9][0-9][0-9]
and create a list such as wks001,wks002,wks003, etc
I know the easiest way in this example would be to simply increment the number through addition, but say I want it to be even more sophisticated later on such as [0-9abc] I'd like to use a more sophisticated tool.
preferable would be some windows capable scripting tech, such as vbscript/powershell but I'm open to other alternatives. I guess I kind of thought this might be something that is done all the time by random number generators and such and would be a programming staple, but I lack the understanding to phrase it correctly I think.
This question already has an answer here:
What is meant by . usage after a number in Fortran?
(1 answer)
Closed 3 years ago.
I'm trying to understand a code in fortran language and i don't understand what does
DIST=AMAX1(0.,DI-DJ) means.
I am really confused with the dot(.) next to 0 .
Any help would be appreciated.
Thanks in advance
MAria
AMAX1 is a function for obtaining the maximum value of two or more (single precision) floating point values. The . is there to indicate that the argument is a floating point value and not an integer. 0. is short for 0.0, FORTRAN allows you to omit the decimal zero.
There are lots of FORTRAN references on the Internet. Here is a quick list of intrinsic functions, for example.
This question already has answers here:
C++ standard output format
(2 answers)
Closed 10 years ago.
I'm still new to C++ so bear with me.
I'm currently making console output applications and I want to make a simple matrix calculator. So I want the user to input 4 values for each element of the matrix. Each element should be at a different xy position on the screen. So it makes up a square, a simple 2x2 matrix.
I don't have a clue how to change the position of text in C++ though. I used the Pascal programming languages before and all you had to do was 'gotoXY(20,40)' followed by a statement.
I know this is probably an easy question, I can't seem to work it out though.
If this is on Windows, you should use SetConsoleCursorPosition. I think I have the right helper class for you here: Helper Class for Console Functions.