In: Computer Science
C++ program that runs on Visual Basic that computes the total cost of books you want to order from an online bookstore. It does so by first asking how many books are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then calls two functions: one for computing the taxes and another for computing the delivery charges. The function which computes delivery charges works as follows: It adds a 5% delivery charge for standard delivery if the total is below $1,000, and an additional 10% charge if you want an expedited next day delivery. The tax and delivery charges are added to the bill and the total cost is displayed.
I wrote the code in very basic manner you will easily understand it(#Edited)
#include <iostream>
using namespace std;
int Tax(int sum)
{
int tax;
tax=(sum*10)/100;
return tax;
}
int Next(int sum,int n)
{
int nextday;
if(n==1)
nextday=(sum*10)/100;
return nextday;
}
int deliveryCharge(int sum)
{
int delivery=0;
if(sum>1000)
{
delivery=sum*10/100;
}
if(sum<1000)
{
delivery=(sum*5)/100;
}
return delivery;
}
int main()
{
int cart_book,book_price,tax,delivery,nextDayCharge,n;
int sum=0,total;
cout << "How many books in your cart?" << endl;
cin>>cart_book;
cout<<"Do you want to pick the order tomorrow if Yes input 1
else if NO 0:";
cin>>n;
while(cart_book!=0)
{
cout<<"Tell me the price of book
no:"<<cart_book<<endl;
cin>>book_price;
sum=sum+book_price;
cart_book--;
}
tax=Tax(sum);//calculate tax on product
delivery=deliveryCharge(sum);//calculate delivery charge
nextDayCharge=Next(sum,n);//next day delivery charge
total=sum+tax+delivery+nextDayCharge;//find out total amount to be
paid after all purchase
cout<<"Total amount to be paid is"<<total;
return 0;
}