Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a loop to keep interacting with the user until they ask to get out (-1) In

ID: 3695293 • Letter: W

Question

Write a loop to keep interacting with the user until they ask to get out (-1) In that loop: 1. Display the current vertex 2. display the possible neighbors from the current vertex 3. ask the user for their choice of a vertex to go to 4. if their choice is -1 then exit 5. if the user enters a value too large or too small report an out of range error 6. if their choice is a valid neighbor then change the current vertex to that choice 7. if their choice is not a valid neighbor then report the vertex they entered is unreachable 8. assume user will enter an int

Explanation / Answer

#include<iostream.h>
#include<conio.h>

void main()
{
   int a[]={1,2,3,4,5,6,7,8,9,10},i,c=5,v;

   while(1)
   {
       if(c>=0 && c<10)
       {
           cout<<"Current vertex="<<c<<endl;

           cout<<"Possible neighbors are "<<c+1<<" and "<<c-1<<endl;
       }
       cout<<"Enter the vertex to go to";
       cin>>v;

       if(v==-1)
           break;
       else if(v>9)
           cout<<"Value too large"<<endl;
       else
           cout<<"Value too small"<<endl;

       c=v;
   }
   getch();
}

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote