Answer to Question #28263 in Action Script | Flash | Flex | ColdFusion for alaa

Question #28263
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.
1
Expert's answer
2013-04-15T09:32:46-0400
#include <iostream>
#include <string>
#include <conio.h>

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;
}

int c;
cin>>c;
return 0;
}



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS