C Quick loops help A robot travels across a 30 foot room Eve
C++
Quick loops help
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...\"! 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.Solution
#include<iostream>
using namespace std;
int main()
{
int roomsize = 30;
int distance = 0;
cout << \"How far would you like the roboto to travel?\";
cin >> distance; // Taking the distance from user
cout << distance << \" feet\" << endl;// Printing the distance given by user
if(distance > roomsize)//Checking whether user has given the roomsize
{
cout << \"Distance given is more than roomsize\"<<endl;
return 0;//Exit if distance given is more than roomsize
}
int i=0;
do
{
if(i==distance)//Checking whether robo reached the given distance. If it reached print I made it
{
cout << \"I made it!\" << endl;
break;
}
i = i+1;//Travelled 1 feet
cout<<i<<\" feet\\t\";//Printing that it reached 1 feet
}while( 1 );
cout<< \"I can only travel \"<<roomsize-distance<<\" more feet.\"<<endl;
return 0;
}
