81.3k views
2 votes
Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents". 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".

User TheAptKid
by
5.3k points

1 Answer

6 votes

Answer:

// here is program in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variable

int price;

cout<<"enter the price: ";

// read the price

cin>>price;

// find the dollars

int doll=price/100;

// find the cents

int cent=price%100;

// print the dollars and cents

cout<<doll<<" dollars and "<<cent<<" cents.";

return 0;

}

Step-by-step explanation:

Read the price from user and assign it to variable "price".Then find the dollars by dividing the price with 100 and to find cents calculate modulus 100 of price. Then print both the value.

Output:

enter the price: 4321

43 dollars and 21 cents.

User Matthijs Hollemans
by
5.4k points