473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem linked list and struct

4
I have to make little program with linked list and structs. but I'm a little stuck atm.
de task is pritty easy, I need to make a tree and in every node there is a question depending on the anwer u give he should take the 'left' solution or the 'right' solution.
for example :
Do you want some soup? j/n ?
j -> you still want some soup?
n-> u want some foot? j/n?

so this is bit the task.
I came up with some thing like this:


#include <iostream>
#include <string>
using namespace std;

struct node{
string question;
struct node *yes, *no;
};



void question(node *bla)
{
cout << bla->vraag << endl;
char *ch;
cin >> ch;
if (ch="j")
question(bla-yes);
if (ch="n");
question(bla->no);
}



int main()
{
node *A, *B, *C, *D, *E;
A = new node;
B = new node;
C = new node;
D = new node;
E = new node;

A->yes=B;
A->no=C;
B->yes=C;
B->no=C;
C->yes=D;
C->no=E;
D->yes=E;
D->no=E;



A->question="U want some soup j/n";
B->question="U want some soup after j/n";
C->question="u want some food j/n";
D->question="U want some food after j/n";
E->question="U want to drink some j/n";

vraag(A);



return 0;
};

I pritty new in c++ but I would think this should work but it doesn't .
any one could help me?
ty
Nov 26 '06 #1
4 1490
horace1
1,510 Expert 1GB
your function question() had a couple of errors
I think this fixes them
Expand|Select|Wrap|Line Numbers
  1. void question(node *bla)
  2. {
  3. cout << bla->question << endl;  // ** change vraag to question
  4. char *ch;
  5. cin >> ch;
  6. if (ch="j")   
  7. question(bla->yes);  // ** fixed ->
  8. if (ch="n");
  9. question(bla->no);
  10. }
  11.  
the next error is in main() where you call
Expand|Select|Wrap|Line Numbers
  1. vraag(A);
  2.  
which does not exist in the code
Nov 26 '06 #2
Rhino
4
I translated it :)
vraag = question
and your fixes don't fix the problem I get :s.
my Dev-c++ give no errors. but he crashes when I execute
Nov 26 '06 #3
horace1
1,510 Expert 1GB
I translated it :)
vraag = question
and your fixes don't fix the problem I get :s.
my Dev-c++ give no errors. but he crashes when I execute
a few more errors in question, e.g.
Expand|Select|Wrap|Line Numbers
  1. void question(node *bla)
  2. {
  3. cout << bla->question << endl;  // ** change vraag to question
  4. char ch;                       // ** removed *
  5. cin >> ch;
  6. if (ch=='n')                    // **changed = to == and " to '
  7. question(bla->yes);              // ** fixed ->
  8. if (ch=='n');                   // ** change = to == and " to '
  9. question(bla->no);
  10. }
  11.  
i now executes until you run off the end of your list
Nov 26 '06 #4
Rhino
4
Ty very much
It where dumb error.
Nov 26 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dream Catcher | last post by:
1. I don't know once the node is located, how to return that node. Should I return pointer to that node or should I return the struct of that node. 2. Also how to do the fn call in main for that...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
10
by: Ben | last post by:
Hi, I am a newbie with C and am trying to get a simple linked list working for my program. The structure of each linked list stores the char *data and *next referencing to the next link. The...
12
by: Eugen J. Sobchenko | last post by:
Hi! I'm writing function which swaps two arbitrary elements of double-linked list. References to the next element of list must be unique or NULL (even during swap procedure), the same condition...
4
by: JS | last post by:
I have a file called test.c. There I create a pointer to a pcb struct: struct pcb {   void *(*start_routine) (void *);   void *arg;   jmp_buf state;   int    stack; }; ...
57
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
11
by: bofh1234 | last post by:
Hello, I am having a problem with linked lists. My program is based on a client server model. The client sends some packets of data to the server. The server reads those packets and is...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.