When using commas in commandprompt, it goes crazy.

So, I'm making this calculator that can calculate everything from addition to squareroots and logorithms. It is a console application, and I've constructed it so you get options to choose whatever math problem you want to solve. For an example you can type the number "1" to solve additions. Now to the problem. If I want to add up two decimal numbers, I will have to use a dot. If I try to use a comma, the console goes crazy and it's flickering like hell. I'm used to using commas in decimal numbers, and not dots. Therefor I'd like to make it understand that commas are also accepted as a dot.

It's hard to explain aha, I hope you get what I mean... I'll just add a code for my addition function.

FYI: Yes, I know, the variable "plusResult" isn't being used in the function, but that's for some later on upgrades ;D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once

#include <iostream>

using namespace std;

void Plus()
{
	double firstValue, secondValue, plusResult;

		cout << "~ ADDITION ~" << endl << endl;
		cout << "Enter your first number: ";
		cin >> firstValue;
		cout << "Enter your second value: ";
		cin >> secondValue;
		cout << "" << endl;
		cout << firstValue << " + " << secondValue << " = " << firstValue + secondValue << endl << endl;

		cout << "----------------------------------------\n" << endl;
}
Last edited on
You want to change the locale.

https://stackoverflow.com/questions/15220861/how-can-i-set-the-comma-to-be-a-decimal-point
http://www.cplusplus.com/reference/ios/ios/imbue/

So you call cout.imbue() / cin.imbue() either with your system locale as shown or a custom one you can create.

Not sure if there is a good way to handle both without switching locales though. You could also read it as a string and parse it yourself.
Last edited on
Topic archived. No new replies allowed.