Write a program that takes a dollar amount as a string input

Assignment Help Computer Engineering
Reference no: EM132211470

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 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 source file for how it is done in C++. Perform the same operation using C.

#include <iostream>
#include <iomanip>

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: \n";
cout << s << endl;

return 0;
}

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

Convert this C++ code to C only

Reference no: EM132211470

Questions Cloud

Write a program that takes a single number from the user : Write a program that takes a single number from the user and returns the number multiplied by the number+7.
Write a program for alphabetic characters : Write a program that requests the user to enter an alphabetic character. Then convert the character from upper case to lower case or lower case to upper case.
Explain how and why the overflow flag was affected : Explain how and why the Overflow flag was affected by each instruction in microprocessor Assembly Language.
Define two public member functions which can be used : Define two public member functions which can be used for inputting data and for showing output of entered data.
Write a program that takes a dollar amount as a string input : 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.
Write a program that will sort a basket of clothes : Write a program that will sort a basket of clothes into their proper drawers. If you were not aware you are sort clothes by their type in this order.
Critically health and safety policy in place : NT 2065 Health and Safety in the Workplace - B.Sc. (Hons) Health, Safety and Environmental Management - Evaluate critically health and safety policy in place
Generate the table only when the button is pressed : Write a program, using either a for-loop, that when a button is clicked on the first page, a function is called that writes a html table of Celsius temperatures
Write a program that will take integers from the user : Write a program that will take 7 integers from the user, store them in an array. Write three functions which takes the aforementioned array as input.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Explain the diagrams of the willowbrook school

Take 1 major process illustrated in the level 0 diagram and draw a level 1 diagram of the major process. Explain the 3 diagrams of the Willowbrook School.

  How state might impact the investigator gathering data

Describe the state, and how it might impact the investigator gathering data. Also discuss alternatives and work around to the device state.

  What factors are important in your decision

Decide what factors are important in your decision as to which computer to buy and list them. After you select the system you would like to buy, identify which terms refer to hardware and which refer to software.

  How many bytes does this string take in the memory

If a string is stored at the memory address 0 times 20008000 and the string is "Cortex-M", show the memory content in hex format starting at 0 times 20008000.

  Define the loss of confidentiality and integrity

Write a report discussing security vulnerabilities that can lead to the loss of confidentiality, integrity, availability, authenticity, or accountability

  In what ways can an html form element acquire focus

In what ways can an HTML form element acquire focus? Describe the approach to addressing HTML elements using forms and elements.

  How does nat help with scalability

Class, think about what you have read this week. How does NAT help with scalability and what does the future look like for NAT?

  Which web site is your favorite

Which site would you recommend or use to help a small business wanting to get into e-commerce? Why?

  Cloud to provide crm installations

What "Cloud" can provide to the CRM installations in order to ease the adoption of such systems?

  Imagine you are asked to head a non-computerized department

Now assume you would like to connect the internal network you devised in Q1 to the outside world. What are the steps you consider to follow? And what are the additional equipment/software you would purchase and why?

  Examine the influence of web-based information on global

today the internet provides an unprecedented amount of information by way of blogs videos and podcasts. conduct a

  Illustrate the constraint graph

Illustrate the constraint graph

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd