Question: Well I have to input a number correctly with comma's and a decimal. My input would be 243,111.11 and the output would come out as 2,43,,111.11
Do I have to create additional for loops statements for each digits and check for comma's/decimal? I almost scrapped this code for attempting to try switch statements. All I seek if if i'm on the right track, and any advice/tip is appreciated. Thus far:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
int main() {
using namespace std;
char myStr[256];
cout << "Enter Any integers ";
cin.getline(myStr,256);
int numDigits = strchr(myStr, '.') - myStr;
int i, distance;
for(i=0; myStr[i] != '\0'; i++) {
putchar(myStr[i]);
distance = numDigits - i - 1;
if(distance > 0 && distance%3 == 0) putchar(',');
}
return 0;
}