Server IP : 172.16.15.8 / Your IP : 52.15.238.221 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/cathomas/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
//----------------------------------------------------------------------------- // Programming Assignment #2 // // Written by C A Thomas // September 2008 // // Purpose: To calculate the cost of the gasoline, the price of a wash, // the total cost of the gasoline and wash, and the number of // discount points earned at the VWC Service Station and Car // Wash. //----------------------------------------------------------------------------- //-----------------Proprocessor Section---------------------------------------- #include <iostream> #include <iomanip> #include <cmath> using namespace std; //-----------------Main Function----------------------------------------------- int main () { //----------------Variables and Constants------------------------------------- int numofdp, // number of discount points earned numofgalint; // number of gallons purchase int float numofgal, // number of gallons purchase costofwash, // cost of carwash costofgas, // cost of gas totalcost; // total cost of gas and wash char typeofgas; // regular, premium, or super //----------------Imput Phase------------------------------------------------- cout << "\n\n Welcome to the VWC Service and Car Wash price program!" ; cout << "\n\n This program is designed to calculate your spendings/earnings at our business!" ; cout << "\n\n Enter grade of gasoline purchased (r for regular, p for premium, and s for super): "; cin >> typeofgas; cout << "\n Enter Number of gallons purchased: "; cin >> numofgal; //----------------Processing Phase-------------------------------------------- numofgalint = static_cast <int> (numofgal); if (numofgalint <= 5) costofwash = 6; else if (5 < numofgalint && numofgalint < 15) costofwash = 6 - ((6 * .1) * (numofgalint - 5)); else if (numofgalint >= 15) costofwash = 0; if (typeofgas == 'r' || typeofgas == 'R') costofgas = 3.399 * numofgal; else if (typeofgas == 'p' || typeofgas == 'P') costofgas = 3.539 * numofgal; else if (typeofgas == 's' || typeofgas == 'S') costofgas = 3.679 * numofgal; totalcost = costofwash + costofgas; if (typeofgas == 'r' || typeofgas == 'R') numofdp = 3 * numofgalint; else if (typeofgas == 'p' || typeofgas == 'P') numofdp = 4 * numofgalint; else if (typeofgas == 's' || typeofgas == 'S') numofdp = 5 * numofgalint; //----------------Output Phase------------------------------------------------ cout << fixed << setprecision(2) ; // Force fixed point for floats cout << "\n\n ~~~~~~~~~~~~Spendings/Earnings Summary~~~~~~~~~~~~~~\n "; cout << "\n Cost of gasoline $ " << setw(5) << costofgas; cout << "\n Price of car wash $ " << setw(5) << costofwash; if (costofwash == 0) cout << " Free"; cout << "\n Total cost of gasoline and car wash $ " << setw(5) << totalcost << endl; cout << "\n Number of discount points earned " << numofdp << endl; return 0; }