In: Computer Science
#include <iostream>
using namespace std;
double print_instructions() {
cout << "WELCOME TO BandN book stores" << endl;
cout << "Today we have a deal on e-books. Customers will
receive a discount off their entire order.." << endl;
cout << "The discount is 15% off your total order and cost
per book is 8.99." << endl;
cout << "Customers who buy 20 or more e-books will receive
20% off instead." << endl;
cout << endl;
return 0;
}
int no_of_books() {
string s;
cout << "Write yes if you wish to shop : ";
cin >> s;
int n = 0;
if (s == "yes" || s == "YES") {
cout << "Numbers of Books you wish to buy: ";
cin >> n;
cout << endl;
}
return n;
}
double sub_total(int n) {
double s_total = 8.99 * n;
return s_total;
}
double discount(double s_total) {
double dis = s_total * 0.15;
return dis;
}
double total_cost(double s_total, double dis) {
double t_cost = s_total - dis;
return t_cost;
}
double print_results(int n, double s_total, double dis, double
t_cost) {
cout << " Amount of books wish to download : " << n
<< endl;
cout << " The subtotal for books is : " << s_total
<< endl;
cout << " The discount given is : " << dis <<
endl;
cout << " The final cost of book is : " << t_cost
<< endl;
return 0;
}
int main() {
print_instructions();
int n = no_of_books();
if (n > 0)
{
double s_total = sub_total(n);
double dis = discount(s_total);
double t_cost = total_cost(s_total, dis);
print_results(n, s_total, dis, t_cost);
}
else {
cout << "Invalid Number of books!" << endl;
}
return 0;
}
IS THERE ANY OTHER WAY TO WRITE THIS CODE? DIFFERENT FUNCTIONS?? WHAT CHANGES COULD I MAKE?
Hello, Student I hope you are doing good and well in lockdown.
Your Program is fine enough in case of coding which meets the functionalities and achieved So I think you should not need anything in this above code but Yes you should work on its UI and try to add more features if you want to implement in it.
I had modified this in terms of UI and created some changes, you can ask me more in comment section if you needed anything, I am always happy to help.
Please upvote <3
#include <iostream>
using namespace std;
double print_instructions() {
cout << "\n\t\t\t\t\t\tWELCOME TO BandN book stores\n" << endl;
cout<<"\t\t\t\t\t-----------------------------------------------\n"<<endl;
cout <<"\t\tToday we have a deal on e-books. Customers will receive a discount off their entire order.." << endl;
cout << "\t\tThe discount is 15% off your total order and cost per book is 8.99." << endl;
cout << "\t\tCustomers who buy 20 or more e-books will receive 20% off instead." << endl;
cout << endl;
return 0;
}
int no_of_books() {
string s;
cout << "Write yes if you wish to shop [yes/No] : ";
cin >> s;
int n = 0;
if (s == "yes" || s == "YES") {
cout << "\nNumbers of Books you wish to buy: ";
cin >> n;
cout << endl;
} else{
cout<<"\n\t\t\t\t\tThanks for Visiting BandN book stores"<<endl;
}
return n;
}
double sub_total(int n) {
double s_total = 8.99 * n;
return s_total;
}
double discount(double s_total) {
double dis = s_total * 0.15;
return dis;
}
double total_cost(double s_total, double dis) {
double t_cost = s_total - dis;
return t_cost;
}
double print_results(int n, double s_total, double dis, double t_cost) {
cout << " Amount of books wish to download : " << n << endl;
cout << " The subtotal for books is : " << s_total << endl;
cout << " The discount given is : " << dis << endl;
cout << " The final cost of book is : " << t_cost << endl;
cout<< "\n\n\t\t\t\t\tThanks for Purchasing with us!! See you soon Again\n\n";
return 0;
}
int main() {
print_instructions();
int n = no_of_books();
if (n > 0)
{
double s_total = sub_total(n);
double dis = discount(s_total);
double t_cost = total_cost(s_total, dis);
print_results(n, s_total, dis, t_cost);
}
return 0;
}
Screenshots: -
Please upvote or hit that thumbs-up button, it really motivates me<3
And Again feel free to ask in comment section .
Thank you!!
Have a nice day:)