1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
irina [24]
3 years ago
15

Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that p

rints the value of price in the form "X dollars and Y cents" on a line by itself. So, if the value of price was 4321, your code would print "43 dollars and 21 cents". If the value was 501 it would print "5 dollars and 1 cents". If the value was 99 your code would print "0 dollars and 99 cents".
Computers and Technology
1 answer:
Natalija [7]3 years ago
5 0

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  

You might be interested in
List out any five input and output devideos​
monitta
Asks issiaksmskskskejehshsjsjsnsdkxxkdnsabhwssns
4 0
3 years ago
How do computers use logic?
madreJ [45]
They don’t use any logic
8 0
4 years ago
What does it NOT mean for something to be open source?
Readme [11.4K]

Answer:

Free to use but you have to pay a fee to modify

Explanation:

You NEVER have to pay for OPEN SOURCE

5 0
3 years ago
Bunco is a dice throwing game that requires no decisions to be made or skill on the part of the player just luck. In the simples
anygoal [31]
Abcdefghijklmnopqrstuvwxyz now I know my abcs, next time won’t you sing with me :)
8 0
2 years ago
Hi, I need help on a Circle Class Assignment that is due today. If anyone could please help me, I would greatly appreciate it. I
nikklg [1K]

Answer:

hmmm lets see

Explanation:

7 0
3 years ago
Other questions:
  • --- is a set of applications that manages the activities and resources of a computer.
    12·1 answer
  • In nutanix command-line interface (ncli) commands, each entity has a unique set of actions, but a common action across all entit
    15·1 answer
  • Why are rules required for a number system to be useful?
    10·2 answers
  • Is the following an example of social media viral marketing? Indicate your response by selecting Yes or No.
    7·1 answer
  • Which of the following skills do employers in any field expect their employees<br> to have?
    5·1 answer
  • Two-dimensional random walk (20 points). A two-dimensional random walk simulates the behavior of a particle moving in a grid of
    14·1 answer
  • Consider the classes below: public class TestA { public static void main(String[] args) { ​ int x = 2; ​ int y = 20 ​ int counte
    6·1 answer
  • It's fill the gap homework
    7·1 answer
  • What should be entered to make the loop print
    6·1 answer
  • What is one of the benefits of using a library in a program?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!