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 (n4 to n7) of the decision tree
Node n7={"Eat eggs & cereal", nullptr, nullptr};
Node n6={"Is it midday?", &n4, &n5};
Node n5={"Eat pasta", nullptr, nullptr};
Node n4={"Eat a sandwich", nullptr, nullptr};
// Define the intermediate nodes (n2 and n3) of the decision tree
Node n3={"Is it early?", &n7, &n6};
Node n2={"Study", nullptr, nullptr};
// Define the root node (n1) of the decision tree
Node n1={"Are you hungry?", &n3, &n2};
// Set the current node to the root node (n1)
Node* currentNode = &n1;
// 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 (currentNode->yes == nullptr && currentNode->no == nullptr){
// Print the decision and exit the loop
cout "You should: " currentNode->description endl;
break;
} else {
// Print the description of the current node
cout currentNode->description 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 = currentNode->yes;
} else if (answer =='n'|| answer =='N'){
currentNode = currentNode->no;
} else {
cout "Invalid input. Please enter 'y' or 'n'." endl;
}
}
}
return 0;
}
I need help IN C + + PLEASE fixing an error in my

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!