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 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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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

Code:

#include <iostream>

using namespace std;

int main()
{
cout <<"You are 14 mile(s) from campus!" << endl;

int turns = 1;
int distance = 14;
while(turns <=4){
// 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 again!\n";
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 < 0)
{
cout<<distance <<endl;
cout << "You have over-shot your target!";
//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 lose!";
cin.get();
break;
}
else
{
cout << "You haven't reached your target!";
cin.get();
cin.ignore();
cout <<"You lose!";
cin.get();
break;
}
}
else
{
cout << "You are " << distance <<" mile(s) from campus!";
cin.get();
cin.ignore();
cout << "You have won!";
cin.get();
break;
}
}

else
{
if(distance > 0)
{
cout << "You are " << distance <<" mile(s) from campus!"<<endl;

}
else if(distance < 0)
{
cout << "You have over-shot your target!";
cin.get();
cin.ignore();
cout <<"You lose!";
cin.get();
break;
}
else
{
cout << "You are " << distance <<" mile(s) from campus!";
cin.get();
cin.ignore();
cout << "You have won!";
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
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!
Transcribed Image 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
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
Transcribed Image 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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to Coding
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education