Ask Question
11 February, 15:39

Assume you are given three variables, revenue, expenses, and profit, all of type Money (a structured type with two int fields, dollars and cents). Assign to profit the result of subtracting expenses from revenue. Let's make the happy assumption that revenue exceeds expenses. However you still may find that the cents part of expenses exceeds that of revenue. If that is the case you will have to "borrow" 1 from revenue dollars (i. e. subtract 1) and "give" it to revenue's cents (i. e. add 100!) in order to carry out the subtraction properly.

+2
Answers (1)
  1. 11 February, 16:51
    0
    if (revenue. cents - expenses. cents < 0) {

    profit. dollars = revenue. dollars - expenses. dollars - 1;

    profit. cents = 1 - revenue. cents - expenses. cents;

    }

    else{

    profit. dollars = revenue. dollars - expenses. dollars;

    profit. cents = revenue. cents - expenses. cents;

    }

    Explanation:

    We know that profit is given as: revenue - expenses from the question.

    From the given expression above;

    if (revenue. cents - expenses. cents < 0)

    then profit. dollar will be revenue. dollars - expenses. dollars - 1; the 1 is to be carry over to the cent part. And the profit. cent will be 1 - revenue. cents - expenses. cents;

    else the profit. dollars and the profit. cent is computed directly without needing to carry over:

    profit. dollars = revenue. dollars - expenses. dollars;

    profit. cents = revenue. cents - expenses. cents;
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Assume you are given three variables, revenue, expenses, and profit, all of type Money (a structured type with two int fields, dollars and ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers