I get an error when I run this c++ code. Below I have attached the code, prompt and the error I receive. Code: #include using namespace std; int main() { cout > choice; // if the choice is invalid...


I get an error when I run this c++ code. Below I have attached the code, prompt and the error I receive.


Code:


#include


using namespace std;


int main()
{
cout <"you are="" 14="" mile(s)="" from="" campus!"=""><>


int turns = 1;
int distance = 14;
while(turns <>
// ask for the choice
cout < "how="" do="" you="" wish="" to="" travel?="" (1="" bus,="" 2="" subway,="" 3="" jetpack)="" "="">
int choice;
cin >> choice;


// if the choice is invalid ask again
if(choice!= 1 && choice!=2 && choice!=3)
{
cout < "invalid="" choice,="" try="">
continue;
}
else
{
// decrease the required distance based in the choice the user makes
switch (choice)
{
case 1:
distance -= 2;
break;
case 2:
distance -= 5;
break;
case 3:
distance -= 10;
break;
}


if(turns == 4)
{
if(distance != 0)
{
if(distance <>
{
cout<>
cout < "you="" have="" over-shot="" your="">
//waits for user input to go to next line
cin.get();
//empties the buffer so that character can wait for new input,
//i.e., user can press enter again to end the program
cin.ignore();
cout <"you>
cin.get();
break;
}
else
{
cout < "you="" haven't="" reached="" your="">
cin.get();
cin.ignore();
cout <"you>
cin.get();
break;
}
}
else
{
cout < "you="" are="" "="">< distance=""><" mile(s)="" from="">
cin.get();
cin.ignore();
cout < "you="" have="">
cin.get();
break;
}
}


else
{
if(distance > 0)
{
cout < "you="" are="" "="">< distance=""><" mile(s)="" from=""><>


}
else if(distance <>
{
cout < "you="" have="" over-shot="" your="">
cin.get();
cin.ignore();
cout <"you>
cin.get();
break;
}
else
{
cout < "you="" are="" "="">< distance=""><" mile(s)="" from="">
cin.get();
cin.ignore();
cout < "you="" have="">
cin.get();
break;
}
}
turns++;


}
}


return 0;
}


It seems I am missing the part that says "You are 3 mile(s) from campus!↵" and You lose should be all the way at the bottom instead. How can I fix it?


Debugglng Informatlon for Lose. Did not reach destinatlon withln 4 steps<br>DEBUG INFO<br>Your instructor has chosen to give you the following information to help you debug your code and improve your submission.<br>COMPILER STACK TRACE<br>None<br>PROGRAM EXECUTION STACK TRACE<br>None<br>INPUT OF THE TEST CASE<br>4 1<br>6.<br>YOUR CODE'S OUTPUT<br>1 You are 14 mile(s) from campus!<br>2 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 12 mile(s) from campus!<br>3 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 1e mile(s) from campus!<br>4 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 5 mile(s) from campus!<br>5 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You haven't reached your target!You lose!<br>THE CORRECT OUTPUT OF THE TEST CASE<br>1 You are 14 mile(s) from campus!<br>2 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 12 mile(s) from campus!<br>3 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 10 mile(s) from campus!<br>4 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 5 mile(s) from campus!<br>5 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 3 mile(s) from campus!<br>6 You haven't reached your target!<br>7 You lose!<br>
How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 3 mile(s) from campus! > You haven't reached your target! > You lose! PRETTY DIFF This diff is colored to make it clear what parts of the output are wrong. Green indicates things in the correct output that you are missing. red indicates things in your output that shouldn't be there. The - character refers to newlines, so the green character refers a newline you are missing in your output and the red refers to a newline you need to remove from your output. 1 You are 14 mile(s) from campus!e 2 HOw do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 12 mile(s) from campus!e 3 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 1e mile(s) from campus!e How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 5 mile(s) from campus!e How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 3 mile(s) from campus!e 6 You haven't reached your target! You lose! "/>
Extracted text: Debugglng Informatlon for Lose. Did not reach destinatlon withln 4 steps DEBUG INFO Your instructor has chosen to give you the following information to help you debug your code and improve your submission. COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None INPUT OF THE TEST CASE 4 1 6. YOUR CODE'S OUTPUT 1 You are 14 mile(s) from campus! 2 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 12 mile(s) from campus! 3 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 1e mile(s) from campus! 4 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 5 mile(s) from campus! 5 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You haven't reached your target!You lose! THE CORRECT OUTPUT OF THE TEST CASE 1 You are 14 mile(s) from campus! 2 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 12 mile(s) from campus! 3 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 10 mile(s) from campus! 4 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 5 mile(s) from campus! 5 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 3 mile(s) from campus! 6 You haven't reached your target! 7 You lose! "UNIX DIFF OF CORRECT OUTPUT AND YOUR OUTPUT 5c5,7 < how="" do="" you="" wish="" to="" travel?="" (1="" bus,="" 2="" subway,="" 3="" jetpack)="" you="" haven't="" reached="" your="" target!you="" lose!="" |="" no="" newline="" at="" end="" of="" file=""> How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 3 mile(s) from campus! > You haven't reached your target! > You lose! PRETTY DIFF This diff is colored to make it clear what parts of the output are wrong. Green indicates things in the correct output that you are missing. red indicates things in your output that shouldn't be there. The - character refers to newlines, so the green character refers a newline you are missing in your output and the red refers to a newline you need to remove from your output. 1 You are 14 mile(s) from campus!e 2 HOw do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 12 mile(s) from campus!e 3 How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 1e mile(s) from campus!e How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 5 mile(s) from campus!e How do you wish to travel? (1 bus, 2 subway, 3 jetpack) You are 3 mile(s) from campus!e 6 You haven't reached your target! You lose!
3 Campus Travel Game<br>This lab will practice using loops.<br>We will construct a short computer game. Please look at the Test Cases for exact wording.<br>For your game, the player's goal is to reach campus exactiy.<br>The player starts 14 miles away and has up to 4 turns to reach campus.<br>At each tum the play can ride either use a Bus, a Subway, or a Jetpack:<br>Ricling a Bus moves the player forward 2 miles each turn.<br>Riding a Subway moves the player forward 5 miles each tum<br>• Riding a Jetpack moves the player forward 10 mile each turn.<br>Example:<br>You are 14 mile(s) from campus!<br>How do you wish to travel? (1 bus, 2 subway, 3 jetpack)<br>The player chooses one.<br>After each turn, the player is informed how much farther she must travel before reaching campus.<br>Winning/Losing: After the last tum, if the player has reached campus exactly (

Extracted text: 3 Campus Travel Game This lab will practice using loops. We will construct a short computer game. Please look at the Test Cases for exact wording. For your game, the player's goal is to reach campus exactiy. The player starts 14 miles away and has up to 4 turns to reach campus. At each tum the play can ride either use a Bus, a Subway, or a Jetpack: Ricling a Bus moves the player forward 2 miles each turn. Riding a Subway moves the player forward 5 miles each tum • Riding a Jetpack moves the player forward 10 mile each turn. Example: You are 14 mile(s) from campus! How do you wish to travel? (1 bus, 2 subway, 3 jetpack) The player chooses one. After each turn, the player is informed how much farther she must travel before reaching campus. Winning/Losing: After the last tum, if the player has reached campus exactly ("You have won!") Otherwise, explain the problem: "You have over-shot your target!" or "You haven't reached your target!" And then write "You lose!" The game will operate as follows: Report how far the user is from campus – the player starts 14 mile away • For each turn: o Ask user to select transport method (Bus, Subway, or Jetpack) o Report the user's new distance from campus olf the player has reached campus or passed campus and it is not the fourth turn, end the game early – This Is a more challenging step! Make sure the rest of your game works before working on this step. ALSO: Check that the user input is valid (1-3). If the user fails to picka valid number, the program must keep asking the user for a new selection until a valid number is entered. ALSO- you do not lose turns by making an invalid selection. Use this wording: Invalid choice, try again! Requirements: • You must use a loop (while, do-while, or for) to loop through the 4 turns. (The loop can include a condition to allow ending early, if you so choose.) You must use at least one if or switch statement Require the user enters one of three numbers to specify the transport method
Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here