Assume you have a variable sales of type Money where the latter is a structured type with two int fields, dollars and cents. Write a statement that reads two integers from standard input, a dollar amount followed by a cents amount, and store these values in the appropriate fields in sales.

Answer :

Answer:

  1. #include <iostream>
  2. using namespace std;
  3. struct Money{
  4.    int dollar;
  5.    int cents;
  6. };
  7. int main()
  8. {
  9.    Money sales;
  10.    cout<<"Input dollar: ";
  11.    cin>>sales.dollar;
  12.    cout<<"Input cents: ";
  13.    cin>>sales.cents;  
  14.    cout<<"$"<<sales.dollar<<"."<<sales.cents;
  15.    return 0;
  16. }

Explanation:

The solution code is written in C++.

Firstly, create a data structure Money with two int fields, dollar and cents. (Line 4 - 7).

Create a Money type object, sales (Line 11).

Prompt user for input dollar and cents and set the input values to the dollar and cents data fields of sales object (Line 12 - 15).

Print out the dollar and cents from sales object (Line 16).

Other Questions