A robot travels across a 30 foot room Every 12 inches it tra

A robot travels across a 30 foot room. Every 12 inches it travels it indicates that it has traveled \'x feet\'. The user inputs how far across the room it want the robot to go. Upon arrival at the specified distance, it announces...\"I made it!\"(This will happen even if the robot moves 0 feet). The program should also indicate how many more feet the robot could travel before running into a wall. i.e. for an input of 5, the resulting output should be: How far would you like the robot to travel? 5 feet

1 feet 2 feet 3 feet 4 feet 5 feet I made it!

I can only travel 25 more feet.

#include <iostream>
using namespace std;

int main() {
int roomsize = 30;
int distance = 0;
  
cout << \"How far would you like the robot to travel? \";
  
cout <<\"I can only travel \"<< remaining << \" more feet\" << endl;
/* Type your code here. */

return 0;
}

Solution

Please follow the code and comments for description :

CODE :

#include <iostream> // required header files

using namespace std;

int main() { // driver method to run the code
   int roomsize = 30; // required initialisations
   int distance = 0, remaining = 0;

   cout << \"How far would you like the robot to travel? \"; // prompt for the user to enter the data
   cin >> distance; // getting the data to a variable
   for(int i = 1; i <= distance; i++ ) { // iterating over the desired length
       cout << i << \" feet \\t\"; // print the length the robot travelled
   }
   cout << \"I made it!\"; // print the success m0essage
   remaining = roomsize - distance; // calculating the remaining left length of the room
   cout <<\"\ I can only travel \"<< remaining << \" more feet.\" << endl; // print the data to console.
   return 0;
}

OUTPUT :

How far would you like the robot to travel? 5
1 feet    2 feet    3 feet    4 feet    5 feet    I made it!
I can only travel 25 more feet.


Hope this is helpful.

A robot travels across a 30 foot room. Every 12 inches it travels it indicates that it has traveled \'x feet\'. The user inputs how far across the room it want

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site