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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
// Initial Project Week 1. Goal is to create a responsive store.
//Some of these are not used. They are here in case I decided to make alterations and use.
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
#include <iomanip>
// put in place to eliminate the need to type std prior to cin/cout etc. due to C++ being built upon C
using namespace std;
// functions should be before main, and as such are here and below
// This function just displays the store name upon beginning the program
void storeName();
int totalCost(int, int, int, int, int);
void displayGoodbye(string);
// function main begins program execution - variables are identified
int main() {
string userName;
string userAddress;
char userSelection;
char userConfirm;
int starwarsNum = 0, starshipNum = 0, indyNum = 0, futureNum = 0, gfNum = 0;
int starwarsCost = 0, starshipCost = 0, indyCost = 0, futureCost = 0, gfCost = 0;
int total;
bool done = false;
//int userConfirm = 0;
storeName();
cout << "Welcome to J-Mart! So that we may best suit your needs, \
please provide me with your name by typing it here ==> ";
//This is where the username is captured
getline(cin, userName);
cout << "\n" << "We at J-Mart are so excited you chose us for your shopping needs, " << \
userName << "." << "\n\n" << endl;
cout << userName << ", please provide us with your shipping information to better improve \
your shopping experience. Please use the following format: Street Number and Street Name, \
Apartment (if applicable), City, State, Zip Code. ** Of note - we currently can only \
take orders shipping to U.S. addresses and APO addresses. **" << "\n" << endl;
// Here a do...while loop begins to capture the user address and allow for corrections
do {
cout << "Please enter your address here, ==> ";
getline(cin, userAddress);
cout << "\n" << "Thank you so much " << userName << ". We have updated our records. You address is " << userAddress << endl << " Do you need to make \
any changes "<< userName << "? " << "\n" << endl;
cout << "Enter Y for Yes " << "\n" << endl;
cout << "Enter N for No." << "\n" << endl;
cin >> userConfirm;
cin.ignore();
// This is the case to decide if corrections are needed
switch (userConfirm) {
case 'y':
case 'Y':
cout << "\n" << "Sorry, let's correct that issue. Enter your correct address: " << endl;
done = false;
break;
case 'n':
case 'N':
cout << "\n" << "Wonderful! " << userName << ", thanks for providing your shipping information." << endl;
done = true;
break;
default:
cout << "\n" << "It looks like you have made an invalid selection." << endl << endl;
done = false;
}
} while (done != true);
// This do...while loop captures the entirety of the order.
do {
cout << "\n" << "Please select which purchase you would like to make. Make your selections by typing \
the associated number only for each item only." << endl;
cout << "\n" << "1 - Star Wars Complete Box Set - Digital Only - $60 each" << endl;
cout << "\n" << "2 - Starship Troopers Complete Box Set - Digital Only - $30 each" << endl;
cout << "\n" << "3 - Indiana Jones Complete Box Set - Digital Only - $45 each" << endl;
cout << "\n" << "4 - Back to the Future Complete Box Set - Digital Only - $35 each" << endl;
cout << "\n" << "5 - The Godfather Complete Box Set - Digital Only - $50 each" << endl;
cout << "\n" << "6 - Calculate totals and exit." << "\n" << endl;
cin >> userSelection;
//Responses will be output based on user selections. If the user selects 6, the while loop is exited and the program exits.
switch (userSelection) {
case '1':
cout << "\n" << "You have selected Star Wars Complete Box Set. May the force be with you!" << " \
\n" << "How many would you like?" << "\n" << endl;
cin >> starwarsNum;
starwarsCost = starwarsNum * 60;
done = false;
break;
case '2':
cout << "\n" << "Citizen! You have selected Starship Troopers Complete Box Set - the bugs don't stand a chance!" << "\
\n" << "How many would you like?" << "\n" << endl;
cin >> starshipNum;
starshipCost = starshipNum * 30;
done = false;
break;
case '3':
cout << "\n" << "You have selected Indiana Jones Complete Box Set. I hope you like snakes..." << endl;
cout << "\n" << "How many would you like?" << endl;
cin >> indyNum;
indyCost = indyNum * 45;
done = false;
break;
case '4':
cout << "\n" << "Great Scott! You have selected Back to the Future Complete Box Set." << endl;
cout << "\n" << "How many would you like?" << endl;
cin >> futureNum;
futureCost = futureNum * 35;
done = false;
break;
case '5':
cout << "\n" << "You have selected The Godfather Complete Box Set. I'd recommend not sleeping with the fishes while watching this \
film." << "\n" << endl;
cout << "How many would you like?" << endl;
cin >> gfNum;
gfCost = gfNum * 50;
done = false;
break;
case'6':
cout << "Thank you!!!" << endl << endl << endl;
done = true;
break;
default:
cout << "\n" << "Oops. It appears you made an improper selection. Try again." << endl;
done = false;
}
} while (done != true);
cout << userName << ", " << "you have ordered " << starwarsNum << " Star Wars Complete Box Set(s) for a cost of $" << starwarsCost << "." << endl;
cout << "You have ordered " << starshipNum << " Starship Trooper Complete Box Set(s) for a cost of $" << starshipCost << "." << endl;
cout << "You have ordered " << indyNum << " Indianna Jones Complete Box Set(s) for a cost of $" << indyCost << "." << endl;
cout << "You have ordered " << futureNum << " Back to the Future Complete Box Set(s) for a cost of $" << futureCost << "." << endl;
cout << "You have ordered " << gfNum << " God Father Complete Box Set(s) for a cost of $" << gfCost << "." << endl << endl << endl;
// Calling the function totalCost to input into the output statement providing the customer with the final cost
total = totalCost(starwarsCost, starshipCost, indyCost, futureCost, gfCost);
cout << "Your total today comes to $" << total << endl << endl << endl;
displayGoodbye("Thanks again for choosing J-Mart for your video needs!");
return 0;
}
// This function when called calculates the total price of the order
int totalCost(int starwarsCost, int starshipCost, int indyCost, int futureCost, int gfCost)
{
int total = starwarsCost + starshipCost+ indyCost + futureCost + gfCost;
return total;
}
// This function when called displays the store name
void storeName()
{
cout << "\n ---------------" << endl;
cout << "\n J-Mart" << endl;
cout << "\n Video Store" << endl;
cout << "\n ---------------" << endl;
cout << "\n" << "\n" << endl;
}
// This function when called does an output of the message take into the function
void displayGoodbye(string msg) {
cout << msg << endl;
}
|