C String processing/Atof

I want to enter a value as a C string in the form: xxx,xxx,xxx,xxx.xx.
I would input 1,000,000 or 1,000, while using the atof function, and the code would just recognize both numbers as a "1", rather than a million/thousand.

Question: would I have use the "STRLEN" statement, where for a certain amount of digit, I would use ","? I think it was similar to a Social security number coding where at a certain lenght, a "-" would be used.

Any help is appreciated. Here is my coding. Hopefully my questions were clear.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>

int main() { 
using namespace std;
char buffer[256];
double result; 

cout << "Testing " << endl;

cout << "Enter Any integers: ";
cin.getline(buffer,256);

if (atof(buffer) > 0) { 
result = atof(buffer) / 2;
}

cout << endl <<  "The integer you put was: " << buffer << " And dividing the integers "<<  
	result << endl;
return 0;
}
when you enter a number you can either omit the ',' as in 1000 or write some code to handle the ','

example
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
#include <iostream>
#include <string>

int main() { 
using namespace std;
char buffer[256];
char tempBuff[256] = {'\n'};
double result; 
int count = 0;

cout << "Testing " << endl;

cout << "Enter Any integers: ";
cin.getline(buffer,256);

for(int i = 0; i < strlen(buffer); i++)
{
	if(isdigit(buffer[i]))
	{
		tempBuff[count] = buffer[i];
		count++;
	}
}

if (atof(tempBuff) > 0) { 
result = atof(tempBuff) / 2;
}

cout << endl <<  "The integer you put was: " << tempBuff << " And dividing the integers "<<  
	result << endl;
cin.ignore();
return 0;
}
Thanks for the reply Yanson. Appreciate the help, will now try to understand the code, and if I have any troubles, I will acquire further assistance. :)
Topic archived. No new replies allowed.