Question: I need help IN C + + PLEASE fixing an error in my code, the code should match the attached image layout Code: #include #include
I need help IN C PLEASE fixing an error in my code, the code should match the attached image layout
Code:
#include
#include
using namespace std;
Define a struct called Node to represent the nodes of the decision tree
struct Node
string description;
Node yes;
Node no;
;
int main
Define the leaf nodes n to n of the decision tree
Node nEat eggs & cereal", nullptr, nullptr;
Node nIs it midday?", &n &n;
Node nEat pasta", nullptr, nullptr;
Node nEat a sandwich", nullptr, nullptr;
Define the intermediate nodes n and n of the decision tree
Node nIs it early?", &n &n;
Node nStudy nullptr, nullptr;
Define the root node n of the decision tree
Node nAre you hungry?", &n &n;
Set the current node to the root node n
Node currentNode &n;
Enter an infinite while loop to traverse the decision tree
while true
Check if the current node is a leaf node both yes and no pointers are nullptr
if currentNodeyes nullptr && currentNodeno nullptr
Print the decision and exit the loop
cout "You should: currentNodedescription endl;
break;
else
Print the description of the current node
cout currentNodedescription endl;
Read y or n from the user input
char answer;
cin answer;
Update the current node based on the user's answer
if answer y answer Y
currentNode currentNodeyes;
else if answer n answer N
currentNode currentNodeno;
else
cout "Invalid input. Please enter y or n endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
