Question: Write a program that takes a dollar amount (...XXX.XX) as a string input and inserts commas every three digits if the number is large. You

Write a program that takes a dollar amount (...XXX.XX) as a string input and inserts commas every three digits if the number is large. You should search for the "." and then count back three characters from that location, inserting a comma every 3 digits until the character at index 0 is reached. See the attached source file for how it is done in C++. Perform the same operation using C.

#include #include

using namespace std;

void dollarFormat(string &);

int main() { string s; cout << "Enter dollar amount in the form nnnn.nn :"; cin >> s; dollarFormat(s); cout << "Here is the amount formatted: "; cout << s << endl;

return 0; }

void dollarFormat(string ¤cy) { int dp; dp = currency.find('.'); if(dp > 3) { for(int x = dp-3; x > 0; x-= 3) { currency.insert(x, ","); } currency.insert(0, "$"); } }

Convert this C++ code to C only

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!