Write a C++ program that asks for the title of the book, the price of the book and the quantity to buy for the book. Print out the title of the book. If a 20% discount is provided for buying the book, calculate and print out the discounted price for the book. Also, calculate and print out the total cost for buying the books at the discounted price.
using namespace std; //main function int main() { string title;// book title float price;// book price int quantity;// book quantity char ch;//choice //input cout<<"Enter the title of the book: "; cin>>title; cout<<"Enter the price of the book: "; cin>>price; cout<<"Enter the quantity to buy for the book: "; cin>>quantity; cout<<"Is 20% discount is provided for buying the book? (y/n)"; cin>>ch; if(ch=='y'){//Is 20% discount is provided for buying the book price=price-price*0.2; double discountedprice=price*quantity; //show result cout<<title<<" discounted price for this book is "<<price<<" the total cost for buying the books at the discounted price is $"<<discountedprice; }else{//not 20% discount is provided for buying the book //show result double discountedprice=price*quantity; cout<<title<<" price for this book is "<<price<<" the total cost for buying the books at this price is $"<<discountedprice; }
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment