+1 (315) 557-6473 

C++ Program to Find Total Cost of Sold Phones Assignment Solution.


Instructions

Objective
Write a c++ program to find total cost of sold phones in c++.

Requirements and Specifications

Description: Write a C++ assignment program in BASIC that compute total charges for phones sold and displays this information to the screen.
Problem: The program must prompt the user for the price of a phone. Compute the sales tax for this value, and then display the phone price, the dollar amount of the sales tax, and the total charge for this purchase. Sales tax is calculated as 7% of the price of the phone. Total charge is the price plus the sales tax amount.
After all the data has been entered, display a grand total of number of phones sold, and a grand total of all total charges.
This program must use at least two subroutines.
Source Code
#include
float calculate_tax(float price, float TAX)
{
 return price * TAX;
}
float calculate_final(float price, float TAX)
{
 // This function calculates the final price
 float tax_price = calculate_tax(price, TAX);
 return price + tax_price;
}
int main()
{
 // Variable to store total number of phones
 int N = 0;
 // Variable to store grand total
 float grand_total = 0.0;
 // Define tax value
 float TAX = 0.07; // 7%
 float tax_price, final_price;
 while (true)
 {
  // Prompt user for price of the phone
  std::cout << "Enter price (0 to quit): ";
  float price;
  std::cin >> price;
  if (price == 0)// quit
  {
   break;
  }
  else if (price < 0)
  {
   std::cout << "Please enter a positive value for price." << std::endl;
  }
  else
  {
   // Calculate
   tax_price = calculate_tax(price, TAX);
   final_price = calculate_final(price, TAX);
   // Display
   std::cout << "Price: $" << price << std::endl;
   std::cout << "Tax (" << TAX * 100 << "%): $" << tax_price << std::endl;
   std::cout << "-------------------" << std::endl;
   std::cout << "Total: $" << final_price << std::endl << std::endl;
   N++;
   grand_total += final_price;
  }
 }
 // Display info of phones sold
 std::cout << "Total phones sold: " << N << std::endl;
 std::cout << "Grand total: $" << grand_total << std::endl;
}