Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my code but I cant seem to get Quantity to return to the main and I don't know why. I've been coding all

This is my code but I cant seem to get Quantity to return to the main and I don't know why. I've been coding all day. Please help with this simple problem.

#pragma warning( disable : 4700)

#include using namespace std;

//Function Prototypes void getPrice(double& price); //call-by-reference void getQuantity(int quantity); //call-by-value double calcCost(double cost, int quantity); double calcTax(double subtotal, double taxRate);

//Declare the global constants const double TAX_RATE = 0.05;

void main() { //Declare the local constants const double SHIPPING = 10.00;

//Declare local variables int quantity = 0; double price, subtotal, salesTax, total;

//Set the decimal point to 2 positions cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "P07 - Cristian Santos ";

//Get and validate values getPrice(price); getQuantity(quantity);

//Calculate amounts subtotal = calcCost(price, quantity); salesTax = calcTax(subtotal, TAX_RATE); total = subtotal + salesTax + SHIPPING;

//Display the results cout << endl << "Price: \t" << price << endl << "Quantity: \t" << quantity << endl << "Subtotal: \t" << subtotal << endl << "Sales Tax:\t" << salesTax << " at " << TAX_RATE << endl << "Shipping: \t" << SHIPPING << endl << "Total Due:\t" << total << endl; cout << " Thank you! "; return; } // end of main

//Function Definitions void getPrice(double& price) { do { cout << "Enter a value between $5 and $15.00 for the price: "; cin >> price; } while (price < 5 || price > 15); cout << endl; return; }

void getQuantity(int quantity) { do { cout << "Enter a value between 1 and 50 for the quantity: "; cin >> quantity; } while (quantity < 1 || quantity > 50); return ;

}

double calcCost(double price, int quantity) { double subtotal; subtotal = price * quantity; return (subtotal); }

double calcTax(double subtotal, double taxRate) { double amount; amount = subtotal * taxRate; return (amount); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions