Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- sales.cpp
- 2/7/2016, 1.1.0
- Steven Piper, Jordan Prokop, Jesse Winter
- */
- #include <iostream>
- #include <stdlib.h>
- #include <fstream>
- #include <iomanip>
- #include <cmath>
- #include <string>
- using namespace std;
- //conversion rates. Just multiply any usd amount by whatever currency, to convert it to that currency
- double const USD = 1.0;
- double const CAN = 1.39;
- double const BTC = 0.002664;
- double const GBP = 0.69;
- void add();
- //void convertUSD(double& curr, double conversionCurr);
- //prototypes
- void welcomeScreen();
- char getMenuSelection();
- void menuExec(char control);
- int charToInt(char var);
- int main()
- {
- //Greets user
- welcomeScreen();
- do
- {
- //sets selection to what the user enters, after being prompted
- char selection = getMenuSelection();
- //uses what the user enters in, to be ran through the switch statement
- menuExec(selection);
- }
- while (1>0);
- system("pause");
- return 0;
- }
- /*************************************************
- Function: welcomeScreen
- Description:Greets the user
- Input: no input
- Precondition: no precondition
- Postcondition: prints out a greeting before returning
- *************************************************/
- void welcomeScreen()
- {
- cout << "Welcome to the SaleS!\n\n";
- return;
- }
- /*************************************************
- Function:getMenuSelection
- Description: This will prompt the user with menu options
- Input: a single number char value
- Precondition: user input must be valid
- Postcondition: Returns selection, char value between 1-3, and char X
- *************************************************/
- char getMenuSelection()
- {
- char selection = ' ';
- do
- {
- cout.setf(ios::left);
- cout << setw(40) << "What would you like to do?" << endl;
- cout << setw(40) << "|Add a sales record" << setw(10) << "| 1" << endl;
- cout << setw(40) << "|View a sales record" << setw(10) << "| 2" << endl;
- cout << setw(40) << "|Options" << setw(10) << "| 3" << endl;
- cout << setw(40) << "|Exit" << setw(10) << "| X" << endl;
- cout << "-->|";
- cin >> selection;
- cout << endl;
- }
- //If an invalid char is entered, it will repeat. This allows for functions to not worry about values out of bounds
- while (!(selection == '1' || selection == '2' || selection == '3' || selection == 'X' || selection == 'x'));
- return selection;
- }
- /*************************************************
- Function: menuExec
- Description: This takes the char control, that the user entered, and runs it through a switch statement to carry out an action
- Input: char control
- Precondition: char control must be x, X, 1, 2, or 3
- Postcondition: Will run what the user selects
- *************************************************/
- void menuExec(char control)
- {
- //converts the char values to int values, for use in switch statement. X = 0
- int controlInt = charToInt(control);
- //This allows for the switch statement to use Titles instead of numbers
- enum menutitles{EXIT, ADD, VIEW, OPTIONS};
- switch (controlInt)
- {
- case EXIT:
- system("pause");
- exit (1);
- break;
- case ADD:
- add();
- break;
- case VIEW:
- cout << "view";
- //**********************************************
- // insert your function here
- //**********************************************
- break;
- case OPTIONS:
- cout << "options";
- break;
- }
- return;
- }
- /*************************************************
- Function: charToInt
- Description: Converts the user input to an int for the switch statement in menuExec
- Input: char control
- Precondition: char control must be x, X, 1, 2, or 3
- Postcondition: Converts 'x'||'X' = 0, '1' = 1, '2' = 2, '3' = 3
- *************************************************/
- int charToInt(char var)
- {
- int control = 0;
- if (var == 'X' || var == 'x')
- {
- control = 0;
- }
- else if (var == '1')
- {
- control = 1;
- }
- else if (var == '2')
- {
- control = 2;
- }
- else if (var == '3')
- {
- control = 3;
- }
- return control;
- }
- void add()
- {
- string sellerName1;
- string sellerName2;
- double sellerTotalSale = 0;
- ofstream salesOutput;
- salesOutput.open("SalesStats.txt", fstream::app);
- cout << "Please Input First Then Last Name Of Salesperson: ";
- cin >> sellerName1;
- cin >> sellerName2;
- salesOutput << endl << sellerName1 << " " << sellerName2 << " - ";
- cout << "Please Input Total Sales Of Salesperson: ";
- cin >> sellerTotalSale;
- salesOutput << sellerTotalSale;
- salesOutput.close();
- return;
- }
- /**************************************************************************************
- =======================================================================================
- _____ _
- / ____| | |
- | (___ _ __ __ _ _ __ ___ ___ ___ __| | ___
- \___ \| '_ \ / _` | '__/ _ \ / __/ _ \ / _` |/ _ \
- ____) | |_) | (_| | | | __/ | (_| (_) | (_| | __/
- |_____/| .__/ \__,_|_| \___| \___\___/ \__,_|\___|
- | |
- |_|
- and experimentals
- =======================================================================================
- ***************************************************************************************/
- /*************************************************
- Function: convertUSD
- Description: Converts any usd value to whatever currency (conversions at the top, as const ints)
- Input: usd, and amount constant. IE: convertUSD(usdAmount, CAN);
- Precondition: Must have US dollar amount as first parameter, and all caps constant as second parameter.
- Postcondition: Pass by reference first parameter. WARNING: REMEMBER TO CHANGE CURR SIGN,($, £, etc)
- *************************************************/
- /*
- void convertUSD(double& curr, double conversionCurr)
- {
- curr = curr * conversionCurr;
- cout << curr;
- return;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement