I am having trouble figuring out exactly what my first step in Visual C++ would
ID: 669316 • Letter: I
Question
I am having trouble figuring out exactly what my first step in Visual C++ would be. The below is the template and then what the output should be as provided by my instructor.
#include <iostream>
#include <iomanip>
// if / else 3.6 page 73
// while 3.7 page 78
// sentinels 3.9 page 84
// iomanip 3.9 page 91
// increment / decrement 3.12 page 97
// for-loop 4.3 page 118
// do-while 4.5 page 126
// Switch 4.6 page 128
// break / continue 4.7 page 135
// Logical Operators 4.8 page 137
int main()
{
int quoteNumber = 1;
bool customerHappy = false; // are they happy with car?
int carSelection = 0; // used to capture selected car
double carCost = 0; // car cost alone
double upgradeCost = 0; // upgrade cost alone
double totalCost = 0; // car plus upgrades cost
// You are going to DOOO something until the customer has
// selected a car and is happy
do
{
// if(true) will ALWAYS be activated
// TODO: Make this loop run if we haven't selected a car
// yet - get the customer to select one
// if carSelection == 0, then they haven't picked a car yet (hint hint)
if (true)
{
std::cout << "Welcome to Bob's used car lot and chop shop!" << " ";
std::cout << "As you can see we have quite a few to choose from!" << " ";
std::cout << "Which one would you like?:" << " ";
std::cout << "[1] 2005 Vokswagen Beetle ($8,000)" << " ";
std::cout << "[2] 2008 Pontiac G6 ($8,581)" << " ";
std::cout << "[3] 2004 Chevy S-10 ($10,500)" << " ";
std::cout << "[4] 2016 Jeep Patriot ($15,209)" << " ";
std::cout << "[5] 2012 Jeep Wrangler Sport ($24,390)" << " ";
std::cout << "Which car would you like?: ";
std::cin >> carSelection;
// TODO: If the user makes a bad selection, tell them
// TODO: Else, set the carCost and move on to upgrades
// ----------------------------------------------
// Put your code in here! --> hint: use a switch
// ----------------------------------------------
// switch(carSelection)...
// ----------------------------------------------
// This newline will create a space between menus
std::cout << " ";
}
else // Otherwise try to sell them some upgrades!
{
int upgradeSelection = 0; // The users menu choice
int engineLevel = 0; // the upgrade level of engine (0-5 only)
int tireLevel = 0; // the upgrade level of tire (0-5 only)
int rimLevel = 0; // the upgrade level of rims (0-5 only)
int paintLevel = 0; // the upgrade level of paint (0-5 only)
int mufflerLevel = 0; // the upgrade level of muffler (0-5 only)
// while(true) will NEVER stop running
// TODO: Make this while loop exit based on user input
while (true)
{
/////////////////////////////////////////////////////
// TODO: Calculate all of the upgrade costs here
/////////////////////////////////////////////////////
// Upgrades are $100 per level plus the cost of lower upgrades
// Example: Level 1 upgrade is $100
// Example: Level 2 upgrade is $100 + $200 = $300
// Example: Level 3 upgrade is $100 + $200 + $300 = $600
// etc etc etc etc etc etc etc etc etc etc etc etc etc...
// Hint: You might find a for-loop helpful for accumulating an amount
upgradeCost = 0;
//////////////////////////////////////////////////////
// Put your code below each of the comments marked
// for each upgrade type
//////////////////////////////////////////////////////
// Calculate upgrade cost for engine
// i.e. Put code here for engine...
// Calculate upgrade cost for tires
// i.e. Put code here for tires...
// Calculate upgrade cost for rims
// etc
// Calculate upgrade cost for paint
// Calculate upgrade cost for muffler
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// TODO: Make the quote lines below print to look like money
// Example 3.45234 should be --> 3.45
// Think about iomanip
// ---------------------------------------
// Put some code in here
// ---------------------------------------
// ---------------------------------------
// ============================================================
// Don't mess with these lines ================================
// ============================================================
std::cout << "[" << quoteNumber++ << "] "; // Don't touch me
std::cout << " Car($" << carCost << ")"; // Don't touch me
std::cout << " E(" << engineLevel << ")"; // Don't touch me
std::cout << " T(" << tireLevel << ")"; // Don't touch me
std::cout << " R(" << rimLevel << ")"; // Don't touch me
std::cout << " P(" << paintLevel << ")"; // Don't touch me
std::cout << " M(" << mufflerLevel << ")"; // Don't touch me
// Don't touch the following line -- HOWEVER, you should put
// something in the space ABOVE to make this line print like money
std::cout << " Upgrades($" << upgradeCost << ")" << std::endl; // Don't touch me
// ============================================================
// Leave this menu the way it is
std::cout << "Do you want to upgrade your car? ";
std::cout << "[-/+1] Downgrade / Upgrade Engine ";
std::cout << "[-/+2] Downgrade / Upgrade Tires ";
std::cout << "[-/+3] Downgrade / Upgrade Rims ";
std::cout << "[-/+4] Downgrade / Upgrade Paint ";
std::cout << "[-/+5] Downgrade / Upgrade Muffler ";
std::cout << "[ 6] Clear all upgrades ";
std::cout << "[ 7] Reset car ";
std::cout << "[ 8] Buy Car!!! ";
std::cout << "What would you like to do?: ";
std::cin >> upgradeSelection; // can be positive or negative
// TODO: Now operate on the user's selection
// TODO: If the user makes a bad selection, tell them
// -----------------------------------------------------------
// Put your code in here! --> hint: what did you do last time?
// -----------------------------------------------------------
// -----------------------------------------------------------
// This newline will create a space between menus
std::cout << " ";
}
}
// Once again, a while(true) loop will never exit
// TODO: Make this loop exit when a car is selected and the customer is happy
} while (true);
/////////////////////////////////////////////////
// Do not modify these lines
/////////////////////////////////////////////////
totalCost = carCost + upgradeCost; // Don't touch me
std::cout << "Bill: Car($" << carCost << ")"; // Don't touch me
std::cout << " Upgrades($" << upgradeCost << ")"; // Don't touch me
std::cout << " Total ($" << totalCost << ") "; // Don't touch me
/////////////////////////////////////////////////
// these will stop the window from closing
std::cout << "Press ENTER to continue";
std::cin.ignore();
std::cin.get();
}
Output:
Sample Output
Below you will find just one example of the correct output. The assignment link on blackboard has several more to look at.
********************************************************************* ** Legend: RED is user input. ** ** Black should be displayed similarly from your program. ** ********************************************************************* Welcome to Bob's used car lot and chop shop! As you can see we have quite a few to choose from! Which one would you like?: [1] 2005 Vokswagen Beetle ($8,000) [2] 2008 Pontiac G6 ($8,581) [3] 2004 Chevy S-10 ($10,500) [4] 2016 Jeep Patriot ($15,209) [5] 2012 Jeep Wrangler Sport ($24,390) Which car would you like?: 3
[1] Car($10500.00) E(0) T(0) R(0) P(0) M(0) Upgrades($0.00) Do you want to upgrade your car? [-/+1] Downgrade / Upgrade Engine [-/+2] Downgrade / Upgrade Tires [-/+3] Downgrade / Upgrade Rims [-/+4] Downgrade / Upgrade Paint [-/+5] Downgrade / Upgrade Muffler [ 6] Clear all upgrades [ 7] Reset car [ 8] Buy Car!!! What would you like to do?: 1
[2] Car($10500.00) E(1) T(0) R(0) P(0) M(0) Upgrades($100.00) Do you want to upgrade your car? [-/+1] Downgrade / Upgrade Engine [-/+2] Downgrade / Upgrade Tires [-/+3] Downgrade / Upgrade Rims
COP3014 Assignment 3 Fall 2015
2
[-/+4] Downgrade / Upgrade Paint [-/+5] Downgrade / Upgrade Muffler [ 6] Clear all upgrades [ 7] Reset car [ 8] Buy Car!!! What would you like to do?: 1
[3] Car($10500.00) E(2) T(0) R(0) P(0) M(0) Upgrades($300.00) Do you want to upgrade your car? [-/+1] Downgrade / Upgrade Engine [-/+2] Downgrade / Upgrade Tires [-/+3] Downgrade / Upgrade Rims [-/+4] Downgrade / Upgrade Paint [-/+5] Downgrade / Upgrade Muffler [ 6] Clear all upgrades [ 7] Reset car [ 8] Buy Car!!! What would you like to do?: -1
[4] Car($10500.00) E(1) T(0) R(0) P(0) M(0) Upgrades($100.00) Do you want to upgrade your car? [-/+1] Downgrade / Upgrade Engine [-/+2] Downgrade / Upgrade Tires [-/+3] Downgrade / Upgrade Rims [-/+4] Downgrade / Upgrade Paint [-/+5] Downgrade / Upgrade Muffler [ 6] Clear all upgrades [ 7] Reset car [ 8] Buy Car!!! What would you like to do?: 2
[5] Car($10500.00) E(1) T(1) R(0) P(0) M(0) Upgrades($200.00) Do you want to upgrade your car? [-/+1] Downgrade / Upgrade Engine [-/+2] Downgrade / Upgrade Tires [-/+3] Downgrade / Upgrade Rims [-/+4] Downgrade / Upgrade Paint [-/+5] Downgrade / Upgrade Muffler [ 6] Clear all upgrades [ 7] Reset car [ 8] Buy Car!!! What would you like to do?: 8
Bill: Car($10500.00) Upgrades($200.00) Total ($10700.00)
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
// if / else 3.6 page 73
// while 3.7 page 78
// sentinels 3.9 page 84
// iomanip 3.9 page 91
// increment / decrement 3.12 page 97
// for-loop 4.3 page 118
// do-while 4.5 page 126
// Switch 4.6 page 128
// break / continue 4.7 page 135
// Logical Operators 4.8 page 137
int main()
{
int quoteNumber = 1;
bool customerHappy = false; // are they happy with car?
int carSelection = 0; // used to capture selected car
double carCost = 0; // car cost alone
double upgradeCost = 0; // upgrade cost alone
double totalCost = 0; // car plus upgrades cost
// You are going to DOOO something until the customer has
// selected a car and is happy
do
{
// if(true) will ALWAYS be activated
// TODO: Make this loop run if we haven't selected a car
// yet - get the customer to select one
// if carSelection == 0, then they haven't picked a car yet (hint hint)
if (carSelection == 0)
{
std::cout << "Welcome to Bob's used car lot and chop shop!" << " ";
std::cout << "As you can see we have quite a few to choose from!" << " ";
std::cout << "Which one would you like?:" << " ";
std::cout << "[1] 2005 Vokswagen Beetle ($8,000)" << " ";
std::cout << "[2] 2008 Pontiac G6 ($8,581)" << " ";
std::cout << "[3] 2004 Chevy S-10 ($10,500)" << " ";
std::cout << "[4] 2016 Jeep Patriot ($15,209)" << " ";
std::cout << "[5] 2012 Jeep Wrangler Sport ($24,390)" << " ";
std::cout << "Which car would you like?: ";
std::cin >> carSelection;
if (carSelection < 0 || carSelection > 5){
carSelection = 0;
cout << "Bad Selection" << endl;
}
// TODO: If the user makes a bad selection, tell them
// TODO: Else, set the carCost and move on to upgrades
// ----------------------------------------------
// Put your code in here! --> hint: use a switch
// ----------------------------------------------
// switch(carSelection)...
switch (carSelection){
case 1:
carCost = 8000;
break;
case 2:
carCost = 8581;
break;
case 3:
carCost = 10500;
break;
case 4:
carCost = 15209;
break;
case 5:
carCost = 24390;
break;
}
// ----------------------------------------------
// This newline will create a space between menus
std::cout << " ";
}
else // Otherwise try to sell them some upgrades!
{
int upgradeSelection = 0; // The users menu choice
int engineLevel = 0; // the upgrade level of engine (0-5 only)
int tireLevel = 0; // the upgrade level of tire (0-5 only)
int rimLevel = 0; // the upgrade level of rims (0-5 only)
int paintLevel = 0; // the upgrade level of paint (0-5 only)
int mufflerLevel = 0; // the upgrade level of muffler (0-5 only)
// while(true) will NEVER stop running
// TODO: Make this while loop exit based on user input
while (true)
{
/////////////////////////////////////////////////////
// TODO: Calculate all of the upgrade costs here
/////////////////////////////////////////////////////
// Upgrades are $100 per level plus the cost of lower upgrades
// Example: Level 1 upgrade is $100
// Example: Level 2 upgrade is $100 + $200 = $300
// Example: Level 3 upgrade is $100 + $200 + $300 = $600
// etc etc etc etc etc etc etc etc etc etc etc etc etc...
// Hint: You might find a for-loop helpful for accumulating an amount
upgradeCost = 0;
//////////////////////////////////////////////////////
// Put your code below each of the comments marked
// for each upgrade type
//////////////////////////////////////////////////////
// Calculate upgrade cost for engine
upgradeCost += ((engineLevel)* (engineLevel + 1) * 100) / 2;
// i.e. Put code here for engine...
// Calculate upgrade cost for tires
upgradeCost += ((tireLevel)* (tireLevel + 1) * 100) / 2;
// i.e. Put code here for tires...
// Calculate upgrade cost for rims
upgradeCost += ((rimLevel)* (rimLevel + 1) * 100) / 2;
// etc
// Calculate upgrade cost for paint
upgradeCost += ((paintLevel)* (paintLevel + 1) * 100) / 2;
// Calculate upgrade cost for muffler
upgradeCost += ((mufflerLevel)* (mufflerLevel + 1) * 100) / 2;
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// TODO: Make the quote lines below print to look like money
// Example 3.45234 should be --> 3.45
// Think about iomanip
// ---------------------------------------
// Put some code in here
// ---------------------------------------
cout << setprecision(2) << fixed;
// ---------------------------------------
// ============================================================
// Don't mess with these lines ================================
// ============================================================
std::cout << "[" << quoteNumber++ << "] "; // Don't touch me
std::cout << " Car($" << carCost << ")"; // Don't touch me
std::cout << " E(" << engineLevel << ")"; // Don't touch me
std::cout << " T(" << tireLevel << ")"; // Don't touch me
std::cout << " R(" << rimLevel << ")"; // Don't touch me
std::cout << " P(" << paintLevel << ")"; // Don't touch me
std::cout << " M(" << mufflerLevel << ")"; // Don't touch me
// Don't touch the following line -- HOWEVER, you should put
// something in the space ABOVE to make this line print like money
std::cout << " Upgrades($" << upgradeCost << ")" << std::endl; // Don't touch me
// ============================================================
// Leave this menu the way it is
std::cout << "Do you want to upgrade your car? ";
std::cout << "[-/+1] Downgrade / Upgrade Engine ";
std::cout << "[-/+2] Downgrade / Upgrade Tires ";
std::cout << "[-/+3] Downgrade / Upgrade Rims ";
std::cout << "[-/+4] Downgrade / Upgrade Paint ";
std::cout << "[-/+5] Downgrade / Upgrade Muffler ";
std::cout << "[ 6] Clear all upgrades ";
std::cout << "[ 7] Reset car ";
std::cout << "[ 8] Buy Car!!! ";
std::cout << "What would you like to do?: ";
std::cin >> upgradeSelection; // can be positive or negative
// TODO: Now operate on the user's selection
// TODO: If the user makes a bad selection, tell them
// -----------------------------------------------------------
// Put your code in here! --> hint: what did you do last time?
switch (upgradeSelection){
case -1:
if (engineLevel == 0){
cout << "Bad selection" << endl;
}
else{
engineLevel--;
}
break;
case 1:
if (engineLevel == 5){
cout << "Bad selection" << endl;
}
else{
engineLevel++;
}
break;
case -2:
if (tireLevel == 0){
cout << "Bad selection" << endl;
}
else{
tireLevel--;
}
break;
case 2:
if (tireLevel == 5){
cout << "Bad selection" << endl;
}
else{
tireLevel++;
}
break;
case -3:
if (rimLevel == 0){
cout << "Bad selection" << endl;
}
else{
rimLevel--;
}
break;
case 3:
if (rimLevel == 5){
cout << "Bad selection" << endl;
}
else{
rimLevel++;
}
break;
case -4:
if (paintLevel == 0){
cout << "Bad selection" << endl;
}
else{
paintLevel--;
}
break;
case 4:
if (paintLevel == 5){
cout << "Bad selection" << endl;
}
else{
paintLevel++;
}
break;
case -5:
if (mufflerLevel == 0){
cout << "Bad selection" << endl;
}
else{
mufflerLevel--;
}
break;
case 5:
if (mufflerLevel == 5){
cout << "Bad selection" << endl;
}
else{
mufflerLevel++;
}
break;
case 6:
engineLevel = 0;
tireLevel = 0;
rimLevel = 0;
paintLevel = 0;
mufflerLevel = 0;
break;
case 7:
carSelection = 0;
break;
case 8:
customerHappy = true;
break;
}
// -----------------------------------------------------------
// -----------------------------------------------------------
// This newline will create a space between menus
std::cout << " ";
if (carSelection == 0 || customerHappy == true){
break;
}
}
}
if (carSelection != 0 && customerHappy){
break;
}
// Once again, a while(true) loop will never exit
// TODO: Make this loop exit when a car is selected and the customer is happy
} while (true);
/////////////////////////////////////////////////
// Do not modify these lines
/////////////////////////////////////////////////
totalCost = carCost + upgradeCost; // Don't touch me
std::cout << "Bill: Car($" << carCost << ")"; // Don't touch me
std::cout << " Upgrades($" << upgradeCost << ")"; // Don't touch me
std::cout << " Total ($" << totalCost << ") "; // Don't touch me
/////////////////////////////////////////////////
// these will stop the window from closing
std::cout << "Press ENTER to continue";
std::cin.ignore();
std::cin.get();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.