Professional Documents
Culture Documents
Assignment 2 Code
Assignment 2 Code
Assignment 2 Code
//
#include "stdafx.h" //precompiled header, unique to Visual Studio 2015. Remove t
his if you're using a different IDE
#include <iostream>
using namespace std;
int main()
{
//This section instantiates and initializes the variables that are calle
d throughout the function.
int retailPrice = 0; //We have instantiated a variable "retailPrice" of
data type "int" and initialized it to 0.
double discountPrice = 0; //Instantiation" means creating the variable,
i.e "double discountPrice".
int salesTaxPct = 0; //"Initialization means setting the variable to som
e value, i.e " =0;".
double totalDiscount = 0; //It is good practice to instantiate and initi
alize values at the very beginning of a code file--others will be looking for in
puts and outputs of your program.
double totalTax = 0;
double finalPrice = 0;
//This section takes user input to replace the initialized value of reta
ilPrice to whatever the user (you) input into the console when the program runs.
cout << "This is the beginning of my most amazing program ever. It will
do taxes!" << endl;
cout << "To begin, enter a sales price for an item to be purchased (-999
to exit)" << endl;
cin >> retailPrice;
cin.clear(); //I believe this is doing some type of "garbage" disposal.
Probably too high level for you now, but it helps the computer from collecting t
oo much junk in its memory.
cin.ignore(10000, '\n'); //This is ignoring all new characters you input
until a newline exists. So it doesn't pick up any digits after the first one yo
u enter
if (retailPrice == -999) //this is an if-conditional statement that says
"If the user hits -999 as an input, then we will jump to the "finishup" section
and ignore any code up to that section.
{
goto finishup;
}
//This section is taking the discount price--similar to above.
cout << "Enter a discount percentage for this wonderful and lovely item,
my dearest." << endl;
cin >> discountPrice;
cin.clear();
cin.ignore(10000, '\n');
//This section is taking the sales tax--similar to above
cout << "Enter the sales tax for this wonderful and lovely item, my dear
est." << endl;
cin >> salesTaxPct;
cin.clear();
cin.ignore(10000, '\n');
//This section is doing the calculation and math to get your final answe
r.