1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
// includes
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
using namespace std;
// Function prototypes
double elasticityOfDemand(double, double);
double elasticityOfSupply(double, double);
// Start of main
int main(void) {
// Call a function to display my splash screen
showIntro(4, 27, 2012, "Demonstration of void function");
// Variables
char userInput = 'a';
double eD = -99.99;
double eS = -99.99;
double qD = -99.99; // quantity demanded
double pD = -99.99; // price demanded
double qS = -99.99; // quantity supplied
double pS = -99.99; // price supplied
// Prompt the user
cout << "This program will help the user to get the price elasticity of demand, or that of supply." << endl;
cout << "Please follow the direction correctly, and you will get the right value! =)" << endl;
cout << endl << endl;
do {
cout << "Which of the price elasticity value would you like to get?" << endl;
cout << "Type d for demand, or s for supply: " << endl;
cin >> userInput;
// Call the function
eD = elasticityOfDemand(qD,pD);
// Print the output
cout << "When the percentage change in quantity demanded is " << qD << ", and that of price demanded is " << pD << ", " << endl;
cout << "the price elasticity of demand is " << eD << ".";
// Call the function
eS = elasticityOfSupply(qS,pS);
// Print the output
cout << "When the percentage change in quantity supplied is " << qS << ", and that of price supplied is " << pS << ", " << endl;
cout << "the price elasticity of supply is " << eS << ".";
}
return 0;
}
// Function definition
double elasticityOfDemand(double quantityDemanded, double priceDemanded) {
// While-loop
while(userInput == 'd') {
double eDemand = -9.99;
eDemand = quantityDemanded/priceDemanded;
return eDemand;
}
}
double elasticityOfSupply(double quantitySupplied, double priceSupplied) {
// While-loop
While(userInput == 's') {
double eSupply = -9.99;
eSupply = quantitySupplied/priceSupplied;
return eSupply;
}
}
|