Respuesta :
Answer:
The c++ statement to show price in dollars and cents is given.
if ( price < 100 )
{
y = price;
}
else
{
x = price/100;
y = price%100;
}
Explanation:
The program does not take any user input as it is not specified in the question.
All the three variables used are integer variables. The variables to store dollars and cents are initialized to 0.
The integer variable price is initialized inside the program.
The value of price is decomposed in dollars and cents as per the logic shown below.
if ( price < 100 )
{
y = price;
}
else
{
x = price/100;
y = price%100;
}
If value of price is below 100, the value of price is taken as cents.
If value of price is 100 or above, cents are separated by taking modulo of price, and the remaining value is taken as dollars.
This program can be tested by taking different values for the variable price.
The c++ program for the above is as follows.
#include <iostream>
using namespace std;
int main() {
// x shows dollars and y shows cents and are initialized to 0
// price can be initialized to any value for testing
int x = 0, y = 0, price = 1234;
cout << " This program displays the price in dollars and cents. " << endl;
if ( price < 100 )
{
y = price;
}
else
{
// dollar is obtained by taking numbers before decimal
// cents are obtained by taking remainder on division by 100
x = price/100;
y = price%100;
}
cout << x << " dollars and " << y << " cents " << endl;
return 0;
}
OUTPUT
This program displays the price in dollars and cents.
12 dollars and 34 cents