include iostream include string include math int main int argc char ar

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>
#include <math.h>
int main(int argc, char *argv[])
{
std::string str;
std::cout << "Vvedite chislo: ";
std::cin >> str;
std::cout << std::endl;
double result = 0.0;
bool isCommaExist = false;
unsigned counter = 1;
for (int i = 0; i < str.length(); i++)
{
if (str[i] == ',' || str[i] == '.') {
isCommaExist = true;
continue;
}
if (!isCommaExist) {
result = result * 10 + (str[i] - '0');
} else {
result = result + double(str[i] - '0') / std::powl(10, counter);
counter++;
}
}
std::cout << "Double: " << result << std::endl;
system("PAUSE");
return 0;
}